home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / football.cpp < prev    next >
C/C++ Source or Header  |  1996-03-07  |  87KB  |  3,808 lines

  1. /******************************************************************************
  2. ******************************************************************************/
  3. //
  4. // Actua Soccer.    1.9.94
  5. //
  6. //    Programmed by Andy Findlay.
  7. //
  8. /******************************************************************************
  9. ******************************************************************************/
  10.  
  11. #include <malloc.h>
  12. #include "global.h"
  13.  
  14. #include "3deng.h"
  15. #include "mouse.h"
  16. #include "editor.h"
  17. #include "time.h"
  18. #include "front.h"
  19. #include "menu.h"
  20. #include "defines.h"
  21. #include "mallocx.h"
  22. #include "eurofrnt\euro_int.h"
  23.  
  24. extern "C" net_var_start;
  25. extern "C" net_var_end;
  26.  
  27. extern void init_foul(int fouler,char direct,char see=FALSE);
  28.  
  29. extern void set_normal_color(int c);
  30. extern int draw_string(buff_info *buff,int font_no,int x,int y,char *string,unsigned char col,short just);
  31. extern int winrange;
  32. extern int Vbytesperline;
  33.  
  34. extern void mem_test();
  35. extern void setpal();
  36. extern int VESAmode(int *);
  37. extern void VGAmode(unsigned char);
  38. extern void svgacpy(unsigned char *,short,short, short,short);
  39. extern setup_info setup;
  40. extern buff_info main_buff,vidi_buff;
  41.  
  42. extern match_data match_info;
  43. extern char return_doskey;
  44.  
  45. extern team_info game_data[];
  46. extern setup_info setup;
  47. extern match_data match_info;
  48.  
  49.  
  50. short time_table[]={5,10,20,40,90};
  51.  
  52. extern unsigned char *readrawfile(char *filename,unsigned char *address);
  53. extern unsigned char pal[768];
  54.  
  55. extern plyrdat *replay_tab;
  56.  
  57. //#define NET_A
  58.  
  59. #include "audio.h"                            // SOS header
  60.  
  61. #ifdef ECTS
  62. extern void read_config_file();
  63. #endif
  64.  
  65. extern "C" volatile int ux1,ux2,wptr,rptr;
  66. extern "C" volatile short net_error;
  67.  
  68. extern "C" volatile char net_half;
  69.  
  70. /******************************************************************************
  71. ******************************************************************************/
  72.  
  73. #include "defines.h"
  74. #include "glob_var.h"
  75.  
  76. extern void init_off_int(match_player *player);
  77.  
  78. extern void opendebugfile();
  79. extern void closedebugfile();
  80. extern void writeplayerdata();
  81. extern void writecontroldata(int i);
  82.  
  83. extern void do_ref_menu();
  84.  
  85. extern char anykey;
  86.  
  87. extern float set_camera_height;
  88. extern float set_camera_dist;
  89.  
  90. extern void out_mcball_coords();
  91.  
  92. /******************************************************************************
  93. *****************************************************************************/
  94.  
  95. void checksum()
  96. {
  97.     short *v=(short *)&var_start;
  98.     short sum=0;
  99.     do
  100.     {
  101.         sum^=*v;
  102.         v++;
  103.     }while(v<(short *)&var_end);
  104.  
  105.     sprintf(check_str,"%d",sum);
  106.     add_message(check_str,WHITE,TRUE);
  107. }
  108.  
  109. /******************************************************************************
  110. ******************************************************************************/
  111.  
  112. extern void force_penalty();
  113.  
  114. int pen_cnt=100;
  115.  
  116. void make_mtable(int t1,int t2)
  117. {
  118.     float d,min_d,x,y,gx;
  119.     int p;
  120.  
  121.     for (int j=t2; j<t2+10; j++)
  122.     {
  123.         teams[j-1].tm_mark=FALSE;
  124.     }
  125.  
  126.     if (t2<12)
  127. // Team A goals...
  128.         gx=0;
  129.     else
  130. // Team B goals...
  131.         gx=pitch_len;
  132.  
  133.     for (int a=t1; a>t1-10; a--)
  134.     {
  135. // Can't mark guy on ball...
  136.         if ((a!=main_man) && (teams[a-1].guy_on>0))
  137.         {
  138.             x=teams[a-1].tm_x;
  139.             y=teams[a-1].tm_y;
  140.             p=0;
  141.  
  142.             if (calc_dist(gx-x,cntspot_y-y)<MUST_MARK_DIST)
  143. // Close enough to be a threat!!!
  144.             {
  145.                 min_d=5000;
  146.                 for (int i=t2; i<t2+10; i++)
  147.                 {
  148.                     if ((teams[i-1].guy_on>0) && (!teams[i-1].tm_wall)
  149.                         && (!teams[i-1].tm_mark))
  150.                     {
  151.                         if (i<12)
  152.                             d=calc_dist(x-match_tactics1[ball_zone1][i-2][0],
  153.                                            y-match_tactics1[ball_zone1][i-2][1]);
  154.                         else
  155.                             d=calc_dist((pitch_len-x)-match_tactics2[ball_zone2][i-13][0],
  156.                                            (pitch_wid-y)-match_tactics2[ball_zone2][i-13][1]);
  157.                         if (d<min_d)
  158.                         {
  159.                             min_d=d;
  160.                             p=i;
  161.                         }
  162.                     }
  163.                 }
  164.             }
  165.  
  166.             if (p)
  167.             {
  168.                 d=calc_dist(gx-x,cntspot_y-y);
  169.  
  170. // How tightly they mark depends on discipline...
  171.                 x+=(prat*(gx-x)*((192-teams[p-1].tm_disc)/64)/d);
  172.                 y+=(prat*(cntspot_y-y)*((192-teams[p-1].tm_disc)/64)/d);
  173.  
  174.                 teams[p-1].tm_mark=a;
  175.  
  176.                 if (p>11)
  177.                     p-=11;
  178.                 man2man[p-2][0]=(int)x;
  179.                 man2man[p-2][1]=(int)y;
  180.             }
  181.         }
  182.     }
  183. }
  184.  
  185. /******************************************************************************
  186. ******************************************************************************/
  187.  
  188. extern "C" int deb_x;
  189. extern "C" int deb_y;
  190.  
  191. void player_stamina()
  192. {
  193.     short ir,p;
  194.     if (match_time.min!=old_min)
  195.     {
  196.         old_min=match_time.min;
  197.  
  198.         for (short i=0; i<22; i++)
  199.         {
  200.             if (!match_info.GameType)
  201.             {
  202.                 int rank;
  203.                 if ((i<11 && !(match_half&1)) || (i>10 && (match_half&1)))
  204.                     rank=game_data[setup.team_a].ranking;
  205.                 else
  206.                     rank=game_data[setup.team_b].ranking;
  207.  
  208.                 ir=50+(1.4*(COUNTRIES-rank-1));        // 50 - 110
  209.             }
  210.             else
  211.             {
  212.                 if ((i<11 && !(match_half&1)) || (i>10 && (match_half&1)))
  213.                 {
  214. // Team A...
  215.                     if (!(match_half&1))
  216.                     {
  217.                         p=i;
  218.                     }
  219.                     else
  220.                     {
  221.                         p=i-11;
  222.                     }
  223.                     ir=game_data[setup.team_a].players[p].pace+28;
  224.                 }
  225.                 else
  226.                 {
  227. // Team B...
  228.                     if (match_half&1)
  229.                     {
  230.                         p=i;
  231.                     }
  232.                     else
  233.                     {
  234.                         p=i-11;
  235.                     }
  236.                     ir=game_data[setup.team_b].players[p].pace+28;
  237.                 }
  238.             }
  239.  
  240.             int st=teams[i].tm_stam;
  241.             float f=(sin((PI*teams[i].tm_time/120)-(PI/2))+1)/2;
  242.             float t=f*(129-st)/140*ir;
  243.             teams[i].tm_rate=ir-t;
  244. /*
  245.             if ((i==1 && !(match_half&1)) || (i==12 && (match_half&1)))
  246.                 deb_x=teams[i].tm_rate;
  247.             else
  248.                 if (i==1 || i==12)
  249.                     deb_y=teams[i].tm_rate;
  250. */
  251.         }
  252.     }
  253. }
  254.  
  255. /******************************************************************************
  256. ******************************************************************************/
  257.  
  258. // Process Various control flags on each logic cycle...
  259.  
  260. void process_flags()
  261. {
  262. #ifdef EURO96
  263.     player_stamina();
  264. #endif
  265.  
  266. // Text message counter...
  267.     if (message_cnt)
  268.         if (!(--new_text))
  269.             if (--message_cnt)
  270.             {
  271.                 new_text=MESSAGE_TIME;
  272.                 if (++current_mess==MAX_MESSAGES)
  273.                     current_mess=0;
  274.             }
  275.  
  276. // Used for offside rule...
  277.     if (ball_released)
  278.         if (ball_released>0)
  279.             ball_released--;
  280.         else
  281.             ball_released++;
  282.  
  283.     if (play_advantage)
  284.     {
  285. // Referee has seen an indiscretion but is waiting to see who collects ball...
  286.         if (ball_poss)
  287.         {
  288. // Some-one has collected ball!!!
  289.             if ((ball_poss<12 && bad_guy>11) || (ball_poss>11 && bad_guy<12))
  290.             {
  291. // Favoured team has it!
  292.                 play_advantage=FALSE;
  293.             }
  294.             else
  295.             {
  296. // Fouling team has it! (no advantage gained!)
  297.                 retake_foul();
  298.             }
  299.         }
  300.     }
  301.  
  302.     if (just_thrown)
  303.         if (last_touch==throw_in_taker)
  304.             just_thrown--;
  305.         else
  306.             just_thrown=FALSE;
  307.  
  308.     switch(match_mode)
  309.     {
  310.         case(IF_KICK_B):
  311.         case(DF_KICK_B):
  312.         case(CORNER_TL):
  313.         case(CORNER_BL):
  314.             man2man_a=TRUE;
  315.             man2man_b=FALSE;
  316.             break;
  317.  
  318.         case(IF_KICK_A):
  319.         case(DF_KICK_A):
  320.         case(CORNER_TR):
  321.         case(CORNER_BR):
  322.             man2man_b=TRUE;
  323.             man2man_a=FALSE;
  324.             break;
  325.  
  326.         default:
  327.             man2man_a=FALSE;
  328.             man2man_b=FALSE;
  329.             break;
  330.     }
  331.  
  332.     if (man2man_b)
  333. // Team B marking table...
  334.     {
  335.         make_mtable(11,13);
  336.     }
  337.     else
  338.     {
  339.         if (man2man_a)
  340. // Team A marking table...
  341.         {
  342.             make_mtable(22,2);
  343.         }
  344.     }
  345. }
  346.  
  347. /******************************************************************************
  348. *****************************************************************************/
  349.  
  350. void init_line_up()
  351. {
  352.     line_up=LINE_UP_DELAY+40;
  353. }
  354.  
  355. /******************************************************************************
  356. *****************************************************************************/
  357.  
  358. short convert_control(char c)
  359. {
  360.     switch(c)
  361.     {
  362.         case(0):
  363.             return(KEY1_CTRL);
  364.             break;
  365.  
  366.         case(1):
  367.             return(KEY2_CTRL);
  368.             break;
  369.  
  370.         case(2):
  371.             return(JOY1_CTRL);
  372.             break;
  373.  
  374.         case(3):
  375.             return(JOY2_CTRL);
  376.             break;
  377.  
  378.         case(4):
  379.             return(MOUSE_CTRL);
  380.             break;
  381.  
  382.         case(5):
  383.             return(LOGPAD_CTRL);
  384.             break;
  385.  
  386.     }
  387.     return(0);
  388. }
  389.  
  390. /******************************************************************************
  391. *****************************************************************************/
  392.  
  393. short conv_conts_back(char c)
  394. {
  395.     switch(c)
  396.     {
  397.         case(JOY1_CTRL):
  398.             return(2);
  399.             break;
  400.  
  401.         case(JOY2_CTRL):
  402.             return(3);
  403.             break;
  404.  
  405.         case(KEY1_CTRL):
  406.             return(0);
  407.             break;
  408.  
  409.         case(KEY2_CTRL):
  410.             return(1);
  411.             break;
  412.  
  413.         case(MOUSE_CTRL):
  414.             return(4);
  415.             break;
  416.  
  417.         case(LOGPAD_CTRL):
  418.             return(5);
  419.             break;
  420.     }
  421.     return(0);
  422. }
  423.  
  424. /******************************************************************************
  425. *****************************************************************************/
  426.  
  427. void init_rand()
  428. {
  429. // Get it from front-end...
  430.     srand(EUROmatch_info.rand);
  431. }
  432.  
  433. /******************************************************************************
  434. *****************************************************************************/
  435.  
  436. void get_performance()
  437. {
  438.     short p,max_p1,max_p2,min_p1,min_p2,min_p,sp,spa,spb;
  439.  
  440.     float clock=45./time_factor;
  441.  
  442.     for (short i=0; i<22; i++)
  443.     {
  444.         p=0;
  445.         if (teams[i].tm_time>=15)
  446.         {
  447.             if (!i || i==(KP_B-1))
  448.             {
  449. // Keeper performance...
  450.                 p+=PER_KPSAVES*clock*teams[i].tm_kpsaves;
  451.                 p+=PER_GOALSIN*clock*(i<11 ? team_a_goals:team_b_goals);
  452.             }
  453.  
  454.             p+=PER_BOOKINGS*clock*teams[i].tm_book;
  455.             p+=PER_FOULS*clock*teams[i].tm_fouls;
  456.             p+=PER_GOALS*clock*teams[i].tm_goals;
  457.             p+=PER_OGS*clock*teams[i].tm_ogs;
  458.             p+=PER_POSS*clock*teams[i].tm_posst;
  459.             p+=PER_WORK*clock*teams[i].tm_work;
  460.  
  461.             if (teams[i].tm_tacks)
  462.                 p+=PER_TACKS*teams[i].tm_twon/(teams[i].tm_tacks+10/clock);
  463.  
  464.             if (teams[i].tm_shots)
  465.                 p+=PER_SHOTS*teams[i].tm_saved/(teams[i].tm_shots+10/clock);
  466.  
  467.             if (teams[i].tm_pass)
  468.                 p+=PER_PASSES*teams[i].tm_pwon/(teams[i].tm_pass+10/clock);
  469.         }
  470.         else
  471. // Not been on field long enough...
  472.             p=-2000;
  473.  
  474.         performance[i]=p;
  475.     }
  476.  
  477.     max_p1=-1000;
  478.     max_p2=-1000;
  479.     min_p1=1000;
  480.     min_p2=1000;
  481.  
  482.     for (i=0; i<22; i++)
  483.     {
  484.         p=performance[i];
  485.         if (i>10)
  486.         {
  487.             if (p>max_p1)
  488.             {
  489.                 max_p1=p;
  490.                 spa=i+1;
  491.             }
  492.  
  493.             if (p<min_p1)
  494.                 min_p1=p;
  495.         }
  496.  
  497.         if (i<11)
  498.         {
  499.             if (p>max_p2)
  500.             {
  501.                 max_p2=p;
  502.                 spb=i+1;
  503.             }
  504.  
  505.             if (p<min_p2)
  506.                 min_p2=p;
  507.         }
  508.     }
  509.  
  510.     if (max_p1>max_p2)
  511.     {
  512.         sp=max_p1;
  513.         man_of_match=spa;
  514.     }
  515.     else
  516.     {
  517.         sp=max_p2;
  518.         man_of_match=spb;
  519.     }
  520.  
  521.     if (min_p1<min_p2)
  522.         min_p=min_p1;
  523.     else
  524.         min_p=min_p2;
  525.  
  526.     sp-=min_p;
  527.  
  528. // Performance is a percentage of star players...
  529.      
  530.     for (i=0; i<22; i++)
  531.     {
  532.         p=performance[i];
  533.         performance[i]=100.*(p-min_p)/sp;
  534.     }
  535. }
  536.  
  537. /******************************************************************************
  538. *****************************************************************************/
  539.  
  540. // Initialise zero vars...
  541.  
  542. extern char cross_on;
  543. extern "C" short state_checksum;
  544.  
  545. void initialise_vars()
  546. {
  547.     int i;
  548.  
  549.     for (i=0; i<5; i++)
  550.     {
  551.         burst_timer[i]=0;
  552.     }
  553.  
  554.     for (i=0; i<22; i++)
  555.     {
  556.         sel_circle[i]=0;
  557.     }
  558. #ifdef EURO96
  559.     state_checksum=0;
  560.     state_ptr=&state1;
  561.     checksum_ptr=(short *)state_ptr;
  562. #endif
  563.     escape_pending=0;
  564.     man_of_match=0;
  565.     xinfo=0;
  566.     message_cnt=0;
  567.     current_mess=0;
  568.     new_text=0;
  569.     not_ahead=FALSE;
  570.     kick_off=TRUE;
  571.     forced=0;
  572.     keep_timer=0;
  573.     player_on_off=FALSE;
  574.     player_being_subbed=FALSE;
  575.     sub_pending=FALSE;
  576.     booking=FALSE;
  577.  
  578.     stop_clock=FALSE;
  579.     card_is_out=0;
  580.     anykey=FALSE;
  581.     demo_match=FALSE;
  582.     rolling_clock=0;
  583.  
  584.     keep_dive=FALSE;
  585.     hold_up_play=0;
  586.     cross_on=FALSE;
  587.     wall_is_up=FALSE;
  588.     
  589.     comsetp=0;
  590.  
  591.     init_rand();
  592.  
  593. // Timing Vars...
  594.  
  595.     updates=0;
  596.     old_count=0;
  597.  
  598.     crowd_mood_a=0;
  599.     crowd_mood_b=0;
  600.  
  601.     possession=0;
  602.     poss_held=0;
  603.  
  604.     for (i=0; i<11; i++)
  605.     {
  606.         strike[i].t=0;
  607.         strike[i].free=0;
  608.         strike[i].ptype=0;
  609.         strike[i].pplr=0;
  610.         strike[i].gt=0;
  611.         strike[i].x=0;
  612.         strike[i].y=0;
  613.         strike[i].atime=0;
  614.         strike[i].stop=0;
  615.     }
  616.  
  617.     first_time_it=FALSE;
  618.     auto_select=FALSE;
  619.  
  620.     seconds=0;
  621.  
  622.     arrow_on=0;
  623.  
  624.     logic_cnt=0;
  625.  
  626.     ball_move=FALSE;
  627.  
  628.     first_bounce=0;
  629.     swerve=0;
  630.     spin_cnt=0;
  631.     spin_ball=0;
  632.     prediction=FALSE;
  633.     set_xyspin=0;
  634.     set_zspin=0;
  635.  
  636.     ball_horz_ang=0;
  637.     ball_vert_ang=0;
  638.     max_sw_factor=0;
  639.     swerve_factor=0;
  640.     rebound_ball=0;
  641.     headed_ball=0;
  642.     say_names=TRUE;
  643.     fired_a_shot=0;
  644.     comm_pass=0;
  645.     comm_pass_type=0;
  646.  
  647.     keeper_spd=0;
  648.     keeper_down=FALSE;
  649.     save_direction=FALSE;
  650.     keeper_will_save=FALSE;
  651.     keeper_on_grnd=FALSE;
  652.     keeper_contact=0;
  653.     ball_in_goal=FALSE;
  654.     ball_in_hands=FALSE;
  655.     game_action=FALSE;
  656.     throw_cnt=0;
  657.     team_a_goals=0;
  658.     team_b_goals=0;
  659.     last_goal=0;
  660.     scorer_running=FALSE;
  661.     just_scored=0;
  662.     just_thrown=0;
  663.     goal_scorer=0;
  664.     pass_type=0;
  665.     kick_type=0;
  666.     receiver=0;
  667.     cross_now=0;
  668.     must_face=FALSE;
  669.     must_face_time=0;
  670.     must_face_x=0;
  671.     must_face_y=0;
  672.     must_shoot=FALSE;
  673.     chip_pass=FALSE;
  674.     must_pass=FALSE;
  675.     must_punt=FALSE;
  676.  
  677.     keeper_a_in_box=0;
  678.     keeper_b_in_box=0;
  679.     keeper_steps=0;
  680.     save_block=0;
  681.     save_xoff=0;
  682.     save_yoff=0;
  683.     save_zoff=0;
  684.     shot_speed=0;
  685.     scr_x=0;
  686.     scr_y=0;
  687.     ball_speed=0;
  688.     ball_int_speed=0;
  689.     interceptor_a=0;
  690.     interceptor_b=0;
  691.     in_cross_area=0;
  692.     close_in_number=0;
  693.     shooter=0;
  694.     ball_inair=1;
  695.     super_shot=0;
  696.     opponents_near_holder=0;
  697.     opponents_really_close=0;
  698.     int ball_poss=0;
  699.     sender_1_2=0;
  700.     ball_still=0;
  701.     last_touch=0;
  702.     want_pass=0;
  703.     before=0;
  704.     support_me=0;
  705.     pre_kp_touch=0;
  706.     prev_touch=0;
  707.  
  708.     ball_limbo_p=0;
  709.     ball_limbo_on=FALSE;
  710.     ball_limbo_c=0;
  711.  
  712.     ball_released=0;
  713.     cannot_pick_up=0;
  714.     last_user_a=0;
  715.     last_user_b=0;
  716.     last_plr_a=0;
  717.     last_plr_b=0;
  718.     players_off_a=0;
  719.     players_off_b=0;
  720.  
  721.     want_pass_stat=0;
  722.     ball_zone1=0;
  723.     ball_zone2=0;
  724.     ball_out_of_play=0;
  725.  
  726.     receiver_a=0;
  727.     receiver_b=0;
  728.  
  729.     ready_centre=0;
  730.     shot_attempt=0;
  731.  
  732.     force_select=0;
  733.     heading_ball=0;
  734.     flag=0;
  735.  
  736.     rep_camera=0;
  737.     sub_camera=0;
  738.     allow_replay=0;
  739.  
  740.     replay_pos=0;
  741.     old_rep_pos=0;
  742.     replay_cnt=0;
  743.  
  744.     pitch_sprs=0;
  745.  
  746.     fixed_net_user=0;
  747.  
  748.     memset(&auto_users_list_a,0,sizeof(auto_users_list_a));
  749.     memset(&auto_users_list_b,0,sizeof(auto_users_list_b));
  750.     auto_users_a=0;
  751.     auto_users_b=0;
  752.  
  753.     play_ball_a=0;
  754.     play_ball_b=0;
  755.  
  756.     new_select=0;
  757.     auto_intercept=0;
  758.     closest=0;
  759.  
  760.     f1_down=0;
  761.     f2_down=0;
  762.  
  763.     spec_kick_type=0;
  764.     setp_hgt=0;
  765.     setp_power=0;
  766.     setp_kick_x=0;
  767.     setp_kick_y=0;
  768.     setp_bxd=0;
  769.     setp_byd=0;
  770.     setp_bzd=0;
  771.         
  772.     user_taker=0;
  773.     user_controlled=0;
  774.     user_plr=0;
  775.     after_touch_on=FALSE;
  776.     drive_shot=0;
  777.  
  778.     wallx=0;
  779.     wally=0;
  780.     men_in_wall=0;
  781.  
  782.     for (i=0; i<5; i++)
  783.     {
  784.         wguys[i].guy=0;
  785.         wguys[i].x=0;
  786.         wguys[i].y=0;
  787.     }
  788.  
  789.     keeper_pos_x=0;
  790.     keeper_pos_y=0;
  791.  
  792.     centre_guy_1=0;
  793.     centre_guy_2=0;
  794.  
  795.     in_range=0;
  796.     in_header_rng=0;
  797.     in_shot_rng=0;
  798.     taker_x=0;
  799.     taker_y=0;
  800.  
  801.     bad_guy=0;
  802.     direct_fk=FALSE;
  803.  
  804.     play_advantage=0;
  805.  
  806.     set_piece_on=0;
  807.  
  808.     shot_acknowledged=FALSE;
  809.     shot_pending=FALSE;
  810.     real_shot=FALSE;
  811.     shot_missed=0;
  812.     shot_saved=0;
  813.  
  814.     for (i=0; i<10; i++)
  815.     {
  816.         opp_dir_tab[i][0]=0;
  817.         opp_dir_tab[i][1]=0;
  818.         opp_dir_tab[i][2]=0;
  819.     }
  820.  
  821.     offside_now=0;
  822.  
  823.     memset(&tussle_tab,0,sizeof(tussle_tab));
  824.  
  825.     ball_travel=0;
  826.     select_cnt=10;
  827.     in_game=1;
  828.     analogue=1;
  829.  
  830.     ballxdis=12.0, ballydis=2.0, ballzdis=10.0;
  831.     ballx=cntspot_x, bally=cntspot_y, ballz=ball_diam/2;
  832.     prev_ballx=0.0*16, prev_bally=30.0*16, prev_ballz=ball_diam/2;
  833.     ns_ballx=0.0, ns_bally=0.0, ns_ballz=ball_diam/2;
  834.     ball_zspin=0;
  835.     ball_xyspin=0;
  836.     full_zspin=0;
  837.     full_xyspin=0;
  838.     shoot_x=0;
  839.     shoot_y=0;
  840.  
  841.     nearest_a=0,nearest_b=0,old_ltouch=-1,old_ball_poss=-1;
  842.     use_ball_limit=0;
  843.     near_path_a=0;
  844.     near_path_b=0;
  845.     zone1_x=0;
  846.     zone2_x=0;
  847.     zone1_y=0;
  848.     zone2_y=0;
  849.     incident_x=0;
  850.     incident_y=0;
  851.     difficulty=0;
  852.     match_mode=0;
  853.     dead_ball_cnt=0;
  854.     defense_a=0;
  855.     defense_b=0;
  856.     poss_mode=0;
  857.  
  858.     for (i=0; i<50; i++)
  859.     {
  860.         ball_pred_tab[i][0]=ballx;
  861.         ball_pred_tab[i][1]=bally;
  862.         ball_pred_tab[i][2]=ballz;
  863.         ns_ball_pred_tab[i][0]=ballx;
  864.         ns_ball_pred_tab[i][1]=bally;
  865.         ns_ball_pred_tab[i][2]=ballz;
  866.     }
  867.  
  868.     delay_cnt=40;
  869.     play_nums_on=0;
  870.     frame=FALSE;
  871.     frames=0;
  872.     frms_per_sec=0;
  873.     last_second=0;
  874.  
  875.     old_clock=0;
  876.  
  877. }
  878.  
  879. /******************************************************************************
  880. *****************************************************************************/
  881.  
  882. void init_user_controls()
  883. {
  884. #ifdef FRONT_END
  885.     num_of_users=0;
  886. #endif
  887.  
  888.     short home_plrs=EUROmatch_info.TeamA_users;
  889.     short away_plrs=EUROmatch_info.TeamB_users;
  890.  
  891. /*
  892.     short home_plrs=game_data[setup.team_a].player_control;
  893.     short away_plrs=game_data[setup.team_b].player_control;
  894. */
  895.  
  896.     short plrs=0;
  897.     short c;
  898.  
  899.     short pnum=0;
  900.  
  901.     for (short i=1; i<16; i<<=1)
  902.     {
  903.         pnum++;
  904.         if (home_plrs&i)
  905.         {
  906. // User...
  907.             plrs++;
  908.             c=convert_control(EUROmatch_info.CntrlTypes[pnum-1]);
  909.             add_team_user(-1,c);
  910.         }
  911.  
  912.         if (away_plrs&i)
  913.         {
  914. // User...
  915.             plrs++;
  916.             c=convert_control(EUROmatch_info.CntrlTypes[pnum-1]);
  917.             add_team_user(-2,c);
  918.         }
  919.     }
  920. }
  921.  
  922. /******************************************************************************
  923. *****************************************************************************/
  924.  
  925. // Copy buffer to current VESA screen
  926. void svgacpy2(unsigned char *buffpt,short x,short y,short w,short h)
  927.     {
  928.     union REGS regs;
  929.     short i,co;
  930.     char *scrpt;
  931.     int scrdisp=x+Vbytesperline*y;
  932.     char bank=scrdisp/winrange;
  933.  
  934.     scrdisp%=winrange;
  935.     scrpt=(char *)0xa0000+scrdisp;
  936.     regs.x.eax=0x4f05;
  937.     regs.x.ebx=0;
  938.     regs.x.edx=bank;
  939.     int386(16,®s,®s);
  940.     do
  941.         {
  942.         co=MIN((winrange-scrdisp)/Vbytesperline,h);
  943.         for (i=0;i<co;i++)
  944.             {
  945.             memcpy(scrpt,buffpt,640);
  946.             scrpt+=Vbytesperline;
  947.             buffpt+=640;
  948.             h--;
  949.             }
  950.         if (h)
  951.             {
  952.             scrdisp=(scrdisp+(co+1)*Vbytesperline)%winrange;
  953.             co=MIN(Vbytesperline-scrdisp,w);
  954.             memcpy(scrpt,buffpt,co);
  955.              bank++;     
  956.              regs.x.eax=0x4f05;
  957.              regs.x.ebx=0;
  958.              regs.x.edx=bank;
  959.               int386(16,®s,®s);
  960.              if (co!=w) 
  961.                 memcpy((char *)0xa0000,buffpt+co,w-co);
  962.             scrpt=(char *)0xa0000+scrdisp;
  963.             buffpt+=640;
  964.             h--;
  965.              }
  966.         }while (h);
  967.     regs.x.eax=0x4f05;
  968.     regs.x.ebx=0;
  969.     regs.x.edx=0;
  970.     int386(16,®s,®s);
  971.     }
  972.  
  973. /******************************************************************************
  974. *****************************************************************************/
  975.  
  976. void display_endscr()
  977. {
  978.     int vesas[]={0x101,-1};
  979.     unsigned char *scr=(unsigned char *)mallocx(640*480);
  980.  
  981.     readrawfile("rolling.pal",(unsigned char *)pal);        // Laurent's
  982.  
  983.     VESAmode(vesas);
  984.  
  985.     readrawfile("rolling.bm",scr);
  986.  
  987.     svgacpy2(scr,0,0,640,480);
  988.  
  989.     setpal();
  990.  
  991.     return_doskey=TRUE;
  992.  
  993.     getch();
  994.  
  995.     freex(scr);
  996. }
  997.  
  998. /******************************************************************************
  999. *****************************************************************************/
  1000.  
  1001. void display_screen()
  1002. {
  1003.     int vesas[]={0x101,-1};
  1004.     int svesas[]={0x100,-1};
  1005.     unsigned char spal[768];
  1006.  
  1007.     memcpy(spal,pal,768);
  1008.  
  1009.     readrawfile("andy.pal",(unsigned char *)pal);        // Laurent's
  1010.  
  1011.     unsigned short x,y;
  1012.     unsigned char sw;
  1013.  
  1014.     VESAmode(vesas);
  1015.  
  1016.     readrawfile("andy.bm",(unsigned char *)main_buff.buff_start);
  1017.  
  1018.     svgacpy2(main_buff.buff_start,0,0,640,480);
  1019.  
  1020.     setpal();
  1021.  
  1022.     count=1;
  1023.     
  1024.     do{
  1025.         read_joystick(0,&x,&y,&sw);
  1026.         if (!--count)
  1027.         {
  1028.             count=200;
  1029.             pal[768-6]--;
  1030.             pal[768-5]--;
  1031.             pal[768-4]--;
  1032.             setpal();
  1033.         }
  1034.     }while(!sw);
  1035.  
  1036. #ifndef ONE_MACHINE
  1037.     VGAmode(0x13);
  1038. #else
  1039.     VESAmode(svesas);
  1040. #endif
  1041.  
  1042.     memcpy(pal,spal,768);
  1043.     setpal();
  1044. }
  1045.  
  1046. /******************************************************************************
  1047. *****************************************************************************/
  1048.  
  1049. void load_new_tactics()
  1050. {
  1051.     FILE *fp1;
  1052.  
  1053.     if (tactics_a!=old_tac_a)
  1054.     {
  1055. // Load Match tactics...
  1056.         switch(tactics_a)
  1057.         {
  1058.             case(F_4_3_3):
  1059.                 fp1=fopen("tac_433.tac","rb");
  1060.                 break;
  1061.     
  1062.             case(F_5_3_2):
  1063.                 fp1=fopen("tac_532.tac","rb");
  1064.                 break;
  1065.  
  1066.             case(F_6_3_1):
  1067.                 fp1=fopen("tac_631.tac","rb");
  1068.                 break;
  1069.  
  1070.             case(F_4_2_4):
  1071.                 fp1=fopen("tac_424.tac","rb");
  1072.                 break;
  1073.  
  1074.             case(F_5_1_4):
  1075.                 fp1=fopen("tac_514.tac","rb");
  1076.                 break;
  1077.  
  1078.             case(F_4_0_6):
  1079.                 fp1=fopen("tac_406.tac","rb");
  1080.                 break;
  1081.  
  1082.             case(F_3_1_6):
  1083.                 fp1=fopen("tac_316.tac","rb");
  1084.                 break;
  1085.  
  1086.             case(F_4_1_5):
  1087.                 fp1=fopen("tac_415.tac","rb");
  1088.                 break;
  1089.  
  1090.             case(F_5_2_3):
  1091.                 fp1=fopen("tac_523.tac","rb");
  1092.                 break;
  1093.  
  1094.             case(F_4_4_2):
  1095.                 fp1=fopen("tac_442.tac","rb");
  1096.                 break;
  1097.         }
  1098.  
  1099.     // Team A tactics...
  1100.         if (!(match_half&1))
  1101.             fread(match_tactics1,sizeof(int),((32*2)+6)*10*2,fp1);
  1102.         else
  1103.             fread(match_tactics2,sizeof(int),((32*2)+6)*10*2,fp1);
  1104.  
  1105.         fclose(fp1);
  1106.     }
  1107.  
  1108.     if (tactics_b!=old_tac_b)
  1109.     {
  1110. // Load Match tactics...
  1111.         switch(tactics_b)
  1112.         {
  1113.             case(F_4_3_3):
  1114.                 fp1=fopen("tac_433.tac","rb");
  1115.                 break;
  1116.     
  1117.             case(F_5_3_2):
  1118.                 fp1=fopen("tac_532.tac","rb");
  1119.                 break;
  1120.  
  1121.             case(F_6_3_1):
  1122.                 fp1=fopen("tac_631.tac","rb");
  1123.                 break;
  1124.  
  1125.             case(F_4_2_4):
  1126.                 fp1=fopen("tac_424.tac","rb");
  1127.                 break;
  1128.  
  1129.             case(F_5_1_4):
  1130.                 fp1=fopen("tac_514.tac","rb");
  1131.                 break;
  1132.  
  1133.             case(F_4_0_6):
  1134.                 fp1=fopen("tac_406.tac","rb");
  1135.                 break;
  1136.  
  1137.             case(F_3_1_6):
  1138.                 fp1=fopen("tac_316.tac","rb");
  1139.                 break;
  1140.  
  1141.             case(F_4_1_5):
  1142.                 fp1=fopen("tac_415.tac","rb");
  1143.                 break;
  1144.  
  1145.             case(F_5_2_3):
  1146.                 fp1=fopen("tac_523.tac","rb");
  1147.                 break;
  1148.  
  1149.             case(F_4_4_2):
  1150.                 fp1=fopen("tac_442.tac","rb");
  1151.                 break;
  1152.         }
  1153.  
  1154.     // Team B tactics...
  1155.         if (!(match_half&1))
  1156.             fread(match_tactics2,sizeof(int),((32*2)+6)*10*2,fp1);
  1157.         else
  1158.             fread(match_tactics1,sizeof(int),((32*2)+6)*10*2,fp1);
  1159.         fclose(fp1);
  1160.     }
  1161.     old_tac_a=tactics_a;
  1162.     old_tac_b=tactics_b;
  1163. }
  1164.  
  1165.  
  1166. /******************************************************************************
  1167. *****************************************************************************/
  1168.  
  1169. void init_match()
  1170. {
  1171.     sub_pending=0;
  1172.  
  1173.     key_togs[0x0a]=EUROmatch_info.vidi;
  1174.  
  1175. // Initialise Penalty Shoot-out...
  1176.     penalties=0;
  1177.     home_pens_left=5;
  1178.     away_pens_left=5;
  1179.     penalty_game=FALSE;
  1180.     penalty_team=FALSE;
  1181.     penalty_counter=0;
  1182.     pen_taker_a=11;
  1183.     pen_taker_b=22;
  1184.  
  1185.     first_update=TRUE;
  1186.  
  1187.     reset_ball();
  1188.  
  1189.     opt_user=0;
  1190.     subbing_now=FALSE;
  1191.  
  1192.     if (setup.M8)
  1193.         replay_seconds=15;
  1194.     else
  1195.         replay_seconds=0;
  1196.  
  1197.     if (replay_seconds)
  1198.     {
  1199.         replay_tab=(plyrdat *)mallocx(replay_seconds*ncb*20*sizeof(plyrdat));
  1200.         if (replay_tab==NULL)
  1201.         {
  1202.             printf("Ooops... Can't malloc replay buffer!\n");
  1203.             exit(-1);
  1204.         }
  1205.     }
  1206.  
  1207.     auto_intercept=TRUE;
  1208.     end_game=FALSE;
  1209.     allow_replay=FALSE;
  1210.     match_time.min=0;
  1211.     match_time.sec=0;
  1212.     next_mins=0;
  1213.  
  1214.     just_scored=0;
  1215.     set_piece_on=0;
  1216.     team_a_goals=0;
  1217.     team_b_goals=0;
  1218.  
  1219.     if (!network_on)
  1220.         init_user_controls();
  1221.  
  1222.     need_result=(match_info.CompetitionType==2);
  1223.     clock_running=FALSE;
  1224.     team_a=0;
  1225.     team_b=1;
  1226.     match_half=0;
  1227.     last_centre=0;
  1228.     init_line_up();
  1229.  
  1230. // Ects show demo (head to head)...
  1231. #ifdef ECTS
  1232.     read_config_file();
  1233.     display_screen();
  1234. #endif
  1235.  
  1236. /*** Setup Tactics ***/
  1237.     tactics_a=EUROmatch_info.tac_1;
  1238.     tactics_b=EUROmatch_info.tac_2;
  1239.     old_tac_a=-1;        // Force new tactical load!
  1240.     old_tac_b=-1;
  1241.     load_new_tactics();
  1242.  
  1243.     ref_accuracy=EUROmatch_info.referee_vision;
  1244.     ref_strictness=EUROmatch_info.referee_discipline;
  1245.  
  1246. }
  1247.  
  1248. /******************************************************************************
  1249. ******************************************************************************/
  1250.  
  1251. #define COUNTRIES 44
  1252.  
  1253. void init_player_stats(short p)
  1254. {
  1255.     p--;
  1256.     short ps;
  1257.  
  1258.     if ((!(match_half&1) && p<11)
  1259.           || (match_half&1 && p>10))
  1260.     {
  1261. // Team A...
  1262.         if (!(match_half&1))
  1263.         {
  1264.             ps=p;
  1265.         }
  1266.         else
  1267.         {
  1268.             ps=p-11;
  1269.         }
  1270.  
  1271.         if (match_info.GameType)
  1272.         {
  1273. // Simulation Mode!!!
  1274.             teams[p].tm_rate=game_data[setup.team_a].players[ps].pace+28;
  1275.             teams[p].tm_pow=game_data[setup.team_a].players[ps].power+28;
  1276.             teams[p].tm_cont=game_data[setup.team_a].players[ps].control+28;
  1277.             teams[p].tm_flair=game_data[setup.team_a].players[ps].flair+28;
  1278.             teams[p].tm_vis=game_data[setup.team_a].players[ps].vision+28;
  1279.             teams[p].tm_ac=game_data[setup.team_a].players[ps].accuracy+28;
  1280.             teams[p].tm_stam=game_data[setup.team_a].players[ps].stamina+28;
  1281.             teams[p].tm_disc=game_data[setup.team_a].players[ps].discipline+28;
  1282.         }
  1283.         else
  1284.         {
  1285. // Arcade Mode!!!
  1286.             int rank=game_data[setup.team_a].ranking;
  1287.             short avg=50+(1.4*(COUNTRIES-rank-1));  // 50 - 110
  1288.  
  1289.             teams[p].tm_rate=30+(avg/2);
  1290.             teams[p].tm_pow=avg;
  1291.             teams[p].tm_cont=avg;
  1292.             teams[p].tm_flair=avg;
  1293.             teams[p].tm_vis=avg;
  1294.             teams[p].tm_ac=avg;
  1295.             teams[p].tm_stam=avg;
  1296.             teams[p].tm_disc=avg;
  1297.         }
  1298.     }
  1299.     else
  1300.     {
  1301. // Team B...
  1302.         if (match_half&1)
  1303.         {
  1304.             ps=p;
  1305.         }
  1306.         else
  1307.         {
  1308.             ps=p-11;
  1309.         }
  1310.  
  1311.         if (match_info.GameType)
  1312.         {
  1313. // Simulation Mode!!!
  1314.             teams[p].tm_rate=game_data[setup.team_b].players[ps].pace+28;
  1315.             teams[p].tm_pow=game_data[setup.team_b].players[ps].power+28;
  1316.             teams[p].tm_cont=game_data[setup.team_b].players[ps].control+28;
  1317.             teams[p].tm_flair=game_data[setup.team_b].players[ps].flair+28;
  1318.             teams[p].tm_vis=game_data[setup.team_b].players[ps].vision+28;
  1319.             teams[p].tm_ac=game_data[setup.team_b].players[ps].accuracy+28;
  1320.             teams[p].tm_stam=game_data[setup.team_b].players[ps].stamina+28;
  1321.             teams[p].tm_disc=game_data[setup.team_b].players[ps].discipline+28;
  1322.         }
  1323.         else
  1324.         {
  1325. // Arcade Mode!!!
  1326.             int rank=game_data[setup.team_b].ranking;
  1327.             short avg=50+(1.4*(COUNTRIES-rank-1));  // 50 - 110
  1328.  
  1329.             teams[p].tm_rate=30+(avg/2);
  1330.             teams[p].tm_pow=avg;
  1331.             teams[p].tm_cont=avg;
  1332.             teams[p].tm_flair=avg;
  1333.             teams[p].tm_vis=avg;
  1334.             teams[p].tm_ac=avg;
  1335.             teams[p].tm_stam=avg;
  1336.             teams[p].tm_disc=avg;
  1337.         }
  1338.     }
  1339. }
  1340.  
  1341. /******************************************************************************
  1342. ******************************************************************************/
  1343.  
  1344. void process_subs()
  1345. {
  1346.     if (player_being_subbed)
  1347.     {
  1348. // Player has been selected and should come off!
  1349.         if (!teams[player_being_subbed-1].guy_on)
  1350.         {
  1351. // He's off the park... (Bring on new guy!)
  1352.             init_player_stats(player_being_subbed);
  1353.             teams[player_being_subbed-1].shirt=player_coming_on;
  1354.             teams[player_being_subbed-1].tm_trap=FALSE;
  1355.             teams[player_being_subbed-1].int_move=FALSE;
  1356.             teams[player_being_subbed-1].int_cnt=FALSE;
  1357.             reset_ideas(&teams[player_being_subbed-1]);
  1358.             player_being_subbed=FALSE;
  1359.             teams[player_on_off-1].guy_on=TRUE;
  1360.             player_on_off=-player_on_off;            // Coming on!
  1361.             init_off_int(&teams[(-player_on_off)-1]);
  1362.         }
  1363.     }
  1364.     else
  1365.     {
  1366.         if (!player_on_off && sub_pending && (match_mode>=CORNER_TL && match_mode<=DF_KICK_B)
  1367.              && !kickoff)
  1368.         {
  1369.             opt_user=100;        // Substitute instead of options...
  1370.  
  1371. // Some-one is trying to make a substitution...(Who?)
  1372.             if (sub_pending&1)
  1373.                 opt_team=0;
  1374.             else
  1375.                 opt_team=1;
  1376.         }
  1377.     }
  1378. }
  1379.  
  1380. /******************************************************************************
  1381. ******************************************************************************/
  1382.  
  1383. void save_state(save_data *save_it)
  1384. {
  1385.     memcpy(save_it->teams,teams,sizeof(teams));
  1386.     memcpy(&save_it->match_time,&match_time,sizeof(match_time));
  1387.     memcpy(save_it->refs,refs,sizeof(refs));
  1388.     memcpy(save_it->speech_tab,speech_tab,sizeof(speech_tab));
  1389.     memcpy(save_it->wguys,wguys,sizeof(wguys));
  1390.     memcpy(save_it->sel_circle,sel_circle,sizeof(sel_circle));
  1391.     memcpy(save_it->burst_timer,burst_timer,sizeof(burst_timer));
  1392.     memcpy(save_it->auto_users_list_a,auto_users_list_a,sizeof(auto_users_list_a));
  1393.     memcpy(save_it->auto_users_list_b,auto_users_list_b,sizeof(auto_users_list_b));
  1394.     memcpy(save_it->rand1_tab,rand1_tab,sizeof(rand1_tab));
  1395.     memcpy(save_it->rand2_tab,rand2_tab,sizeof(rand2_tab));
  1396.     memcpy(save_it->man2man,man2man,sizeof(man2man));
  1397.     memcpy(save_it->glob_str1,glob_str1,sizeof(glob_str1));
  1398.     memcpy(save_it->glob_str2,glob_str2,sizeof(glob_str2));
  1399.  
  1400.     save_it->sub_pending=sub_pending;
  1401.  
  1402.     save_it->return_12=return_12;
  1403.     save_it->shamed_player=shamed_player;
  1404.     save_it->old_min=old_min;
  1405.     save_it->users_left=users_left;
  1406.     save_it->setp_x=setp_x;
  1407.     save_it->setp_y=setp_y;
  1408.     save_it->setp_wait_cnt=setp_wait_cnt;
  1409.     save_it->frame=frame;
  1410.     save_it->kick_off=kick_off;
  1411.     save_it->keep_timer=keep_timer;
  1412.     save_it->stop_clock=stop_clock;
  1413.     save_it->keep_dive=keep_dive;
  1414.     save_it->hold_up_play=hold_up_play;
  1415.     save_it->wall_is_up=wall_is_up;
  1416.     save_it->card_is_out=card_is_out;
  1417.     save_it->crowd_mood_a=crowd_mood_a;
  1418.     save_it->crowd_mood_b=crowd_mood_b;
  1419.     save_it->possession=possession;
  1420.     save_it->poss_held=poss_held;
  1421.     save_it->arrow_on=arrow_on;
  1422.     save_it->logic_cnt=logic_cnt;
  1423.     save_it->ball_move=ball_move;
  1424.     save_it->first_bounce=first_bounce;
  1425.     save_it->swerve=swerve;
  1426.     save_it->spin_cnt=spin_cnt;
  1427.     save_it->spin_ball=spin_ball;
  1428.     save_it->prediction=prediction;
  1429.     save_it->set_xyspin=set_xyspin;
  1430.     save_it->set_zspin=set_zspin;
  1431.     save_it->ball_horz_ang=ball_horz_ang;
  1432.     save_it->ball_vert_ang=ball_vert_ang;
  1433.     save_it->max_sw_factor=max_sw_factor;
  1434.     save_it->swerve_factor=swerve_factor;
  1435.     save_it->rebound_ball=rebound_ball;
  1436.     save_it->headed_ball=headed_ball;
  1437.     save_it->say_names=say_names;
  1438.     save_it->fired_a_shot=fired_a_shot;
  1439.     save_it->comm_pass=comm_pass;
  1440.     save_it->comm_pass_type=comm_pass_type;
  1441.     save_it->keeper_spd=keeper_spd;
  1442.     save_it->keeper_down=keeper_down;
  1443.     save_it->save_direction=save_direction;
  1444.     save_it->keeper_will_save=keeper_will_save;
  1445.     save_it->keeper_on_grnd=keeper_on_grnd;
  1446.     save_it->keeper_contact=keeper_contact;
  1447.     save_it->ball_in_goal=ball_in_goal;
  1448.     save_it->ball_in_hands=ball_in_hands;
  1449.     save_it->game_action=game_action;
  1450.     save_it->throw_cnt=throw_cnt;
  1451.     save_it->team_a_goals=team_a_goals;
  1452.     save_it->team_b_goals=team_b_goals;
  1453.     save_it->last_goal=last_goal;
  1454.     save_it->scorer_running=scorer_running;
  1455.     save_it->just_scored=just_scored;
  1456.     save_it->just_thrown=just_thrown;
  1457.     save_it->goal_scorer=goal_scorer;
  1458.     save_it->pass_type=pass_type;
  1459.     save_it->kick_type=kick_type;
  1460.     save_it->receiver=receiver;
  1461.     save_it->cross_now=cross_now;
  1462.     save_it->auto_select=auto_select;
  1463.     save_it->must_face=must_face;
  1464.     save_it->must_face_time=must_face_time;
  1465.     save_it->must_face_x=must_face_x;
  1466.     save_it->must_face_y=must_face_y;
  1467.     save_it->must_shoot=must_shoot;
  1468.     save_it->chip_pass=chip_pass;
  1469.     save_it->must_pass=must_pass;
  1470.     save_it->must_punt=must_punt;
  1471.     save_it->keeper_a_in_box=keeper_a_in_box;
  1472.     save_it->keeper_b_in_box=keeper_b_in_box;
  1473.     save_it->keeper_steps=keeper_steps;
  1474.     save_it->save_block=save_block;
  1475.     save_it->save_xoff=save_xoff;
  1476.     save_it->save_yoff=save_yoff;
  1477.     save_it->save_zoff=save_zoff;
  1478.     save_it->shot_speed=shot_speed;
  1479.     save_it->scr_x=scr_x;
  1480.     save_it->scr_y=scr_y;
  1481.     save_it->ball_speed=ball_speed;
  1482.     save_it->ball_int_speed=ball_int_speed;
  1483.     save_it->interceptor_a=interceptor_a;
  1484.     save_it->interceptor_b=interceptor_b;
  1485.     save_it->in_cross_area=in_cross_area;
  1486.     save_it->close_in_number=close_in_number;
  1487.     save_it->shooter=shooter;
  1488.     save_it->ball_inair=ball_inair;
  1489.     save_it->super_shot=super_shot;
  1490.     save_it->opponents_near_holder=opponents_near_holder;
  1491.     save_it->opponents_really_close=opponents_really_close;
  1492.     save_it->ball_poss=ball_poss;
  1493.     save_it->sender_1_2=sender_1_2;
  1494.     save_it->ball_still=ball_still;
  1495.     save_it->last_touch=last_touch;
  1496.     save_it->want_pass=want_pass;
  1497.     save_it->before=before;
  1498.     save_it->support_me=support_me;
  1499.     save_it->pre_kp_touch=pre_kp_touch;
  1500.     save_it->prev_touch=prev_touch;
  1501.     save_it->ball_limbo_p=ball_limbo_p;
  1502.     save_it->ball_limbo_on=ball_limbo_on;
  1503.     save_it->ball_limbo_c=ball_limbo_c;
  1504.     save_it->ball_released=ball_released;
  1505.     save_it->cannot_pick_up=cannot_pick_up;
  1506.     save_it->forced=forced;
  1507.     save_it->last_user_a=last_user_a;
  1508.     save_it->last_user_b=last_user_b;
  1509.     save_it->last_plr_a=last_plr_a;
  1510.     save_it->last_plr_b=last_plr_b;
  1511.     save_it->players_off_a=players_off_a;
  1512.     save_it->players_off_b=players_off_b;
  1513.     save_it->want_pass_stat=want_pass_stat;
  1514.     save_it->ball_zone1=ball_zone1;
  1515.     save_it->ball_zone2=ball_zone2;
  1516.     save_it->ball_out_of_play=ball_out_of_play;
  1517.     save_it->receiver_a=receiver_a;
  1518.     save_it->receiver_b=receiver_b;
  1519.     save_it->ready_centre=ready_centre;
  1520.     save_it->shot_attempt=shot_attempt;
  1521.     save_it->force_select=force_select;
  1522.     save_it->heading_ball=heading_ball;
  1523.     save_it->flag=flag;
  1524.     save_it->rep_camera=rep_camera;
  1525.     save_it->sub_camera=sub_camera;
  1526.     save_it->allow_replay=allow_replay;
  1527.     save_it->replay_pos=replay_pos;
  1528.     save_it->old_rep_pos=old_rep_pos;
  1529.     save_it->replay_cnt=replay_cnt;
  1530.     save_it->pitch_sprs=pitch_sprs;
  1531.     save_it->lp_user=lp_user;
  1532.     save_it->fixed_net_user=fixed_net_user;
  1533.     save_it->auto_users_a=auto_users_a;
  1534.     save_it->auto_users_b=auto_users_b;
  1535.     save_it->play_ball_a=play_ball_a;
  1536.     save_it->play_ball_b=play_ball_b;
  1537.     save_it->new_select=new_select;
  1538.     save_it->auto_intercept=auto_intercept;
  1539.     save_it->closest=closest;
  1540.     save_it->f1_down=f1_down;
  1541.     save_it->f2_down=f2_down;
  1542.     save_it->spec_kick_type=spec_kick_type;
  1543.     save_it->setp_hgt=setp_hgt;
  1544.     save_it->setp_power=setp_power;
  1545.     save_it->setp_kick_x=setp_kick_x;
  1546.     save_it->setp_kick_y=setp_kick_y;
  1547.     save_it->setp_bxd=setp_bxd;
  1548.     save_it->setp_byd=setp_byd;
  1549.     save_it->setp_bzd=setp_bzd;
  1550.     save_it->user_taker=user_taker;
  1551.     save_it->user_taker2=user_taker2;
  1552.     save_it->user_controlled=user_controlled;
  1553.     save_it->user_plr=user_plr;
  1554.     save_it->after_touch_on=after_touch_on;
  1555.     save_it->drive_shot=drive_shot;
  1556.     save_it->newk_shot=newk_shot;
  1557.     save_it->wallx=wallx;
  1558.     save_it->wally=wally;
  1559.     save_it->men_in_wall=men_in_wall;
  1560.     save_it->keeper_pos_x=keeper_pos_x;
  1561.     save_it->keeper_pos_y=keeper_pos_y;
  1562.     save_it->centre_guy_1=centre_guy_1;
  1563.     save_it->centre_guy_2=centre_guy_2;
  1564.     save_it->in_range=in_range;
  1565.     save_it->in_header_rng=in_header_rng;
  1566.     save_it->in_shot_rng=in_shot_rng;
  1567.     save_it->taker_x=taker_x;
  1568.     save_it->taker_y=taker_y;
  1569.     save_it->penalty_shot=penalty_shot;
  1570.     save_it->penalties=penalties;
  1571.     save_it->penalty_game=penalty_game;
  1572.     save_it->home_pens_left=home_pens_left;
  1573.     save_it->away_pens_left=away_pens_left;
  1574.     save_it->penalty_counter=penalty_counter;
  1575.     save_it->pen_taker_a=pen_taker_a;
  1576.     save_it->pen_taker_b=pen_taker_b;
  1577.     save_it->penalty_team=penalty_team;
  1578.     save_it->penalty_taker=penalty_taker;
  1579.     save_it->penalty_taker_a=penalty_taker_a;
  1580.     save_it->penalty_taker_b=penalty_taker_b;
  1581.     save_it->setp_taker=setp_taker;
  1582.     save_it->fkick_taker=fkick_taker;
  1583.     save_it->fkick_taker_a=fkick_taker_a;
  1584.     save_it->fkick_taker_b=fkick_taker_b;
  1585.     save_it->gkick_taker=gkick_taker;
  1586.     save_it->goal_kicker_a=goal_kicker_a;
  1587.     save_it->goal_kicker_b=goal_kicker_b;
  1588.     save_it->corner_taker=corner_taker;
  1589.     save_it->corn_kicker_a=corn_kicker_a;
  1590.     save_it->corn_kicker_b=corn_kicker_b;
  1591.     save_it->ktaker=ktaker;
  1592.     save_it->bad_guy=bad_guy;
  1593.     save_it->direct_fk=direct_fk;
  1594.     save_it->play_advantage=play_advantage;
  1595.     save_it->set_piece_on=set_piece_on;
  1596.     save_it->throw_in_taker=throw_in_taker;
  1597.     save_it->main_man=main_man;
  1598.     save_it->player_num=player_num;
  1599.     save_it->savex=savex;
  1600.     save_it->savey=savey;
  1601.     save_it->savez=savez;
  1602.     save_it->shot_acknowledged=shot_acknowledged;
  1603.     save_it->shot_pending=shot_pending;
  1604.     save_it->real_shot=real_shot;
  1605.     save_it->shot_missed=shot_missed;
  1606.     save_it->shot_saved=shot_saved;
  1607.     save_it->drib_opps=drib_opps;
  1608.     save_it->stop_and_face=stop_and_face;
  1609.     save_it->x_face=x_face;
  1610.     save_it->y_face=y_face;
  1611.     save_it->offside_now=offside_now;
  1612.     save_it->can_be_offside=can_be_offside;
  1613.     save_it->ref_accuracy=ref_accuracy;
  1614.     save_it->ref_strictness=ref_strictness;
  1615.     save_it->ref_wait=ref_wait;
  1616.     save_it->tussle_ptr=tussle_ptr;
  1617.     save_it->crowd_a=crowd_a;
  1618.     save_it->crowd_b=crowd_b;
  1619.     save_it->kickoff=kickoff;
  1620.     save_it->end_game=end_game;
  1621.     save_it->team_a=team_a;
  1622.     save_it->team_b=team_b;
  1623.     save_it->last_centre=last_centre;
  1624.     save_it->need_result=need_result;
  1625.     save_it->injury_time=injury_time;
  1626.     save_it->special_move=special_move;
  1627.     save_it->match_half=match_half;
  1628.     save_it->opt_user=opt_user;
  1629.     save_it->opt_team=opt_team;
  1630.     save_it->options_on=options_on;
  1631.     save_it->line_up=line_up;
  1632.     save_it->player_being_subbed=player_being_subbed;
  1633.     save_it->player_on_off=player_on_off;
  1634.     save_it->player_coming_on=player_coming_on;
  1635.     save_it->booking=booking;
  1636.     save_it->subbing_now=subbing_now;
  1637.     save_it->first_update=first_update;
  1638.     save_it->newdx=newdx;
  1639.     save_it->newdy=newdy;
  1640.     save_it->wind_on=wind_on;
  1641.     save_it->wind_d_trend=wind_d_trend;
  1642.     save_it->wind_s_trend=wind_s_trend;
  1643.     save_it->wind_x=wind_x;
  1644.     save_it->wind_y=wind_y;
  1645.     save_it->wind_speed=wind_speed;
  1646.     save_it->init_wind_x=init_wind_x;
  1647.     save_it->init_wind_y=init_wind_y;
  1648.     save_it->init_wind_speed=init_wind_speed;
  1649.     save_it->wind_var_ang=wind_var_ang;
  1650.     save_it->tactics_a=tactics_a;
  1651.     save_it->tactics_b=tactics_b;
  1652.     save_it->old_tac_a=old_tac_a;
  1653.     save_it->old_tac_b=old_tac_b;
  1654.     save_it->afr1=afr1;
  1655.     save_it->afr2=afr2;
  1656.     save_it->man2man_a=man2man_a;
  1657.     save_it->man2man_b=man2man_b;
  1658.     save_it->next_mins=next_mins;
  1659.     save_it->time_factor=time_factor;
  1660.     save_it->clock_running=clock_running;
  1661.     save_it->demo_match=demo_match;
  1662.     save_it->rolling_clock=rolling_clock;
  1663.     save_it->arrow_guy=arrow_guy;
  1664.     save_it->rand_seed=rand_seed;
  1665.     save_it->seed=seed;
  1666.     save_it->man_down=man_down;
  1667.     save_it->launch_type=launch_type;
  1668.     save_it->launch_x=launch_x;
  1669.     save_it->launch_y=launch_y;
  1670.     save_it->ballxdis=ballxdis;
  1671.     save_it->ballydis=ballydis;
  1672.     save_it->ballzdis=ballzdis;
  1673.     save_it->ballx=ballx;
  1674.     save_it->bally=bally;
  1675.     save_it->ballz=ballz;
  1676.     save_it->ballx_out=ballx_out;
  1677.     save_it->bally_out=bally_out;
  1678.     save_it->ballz_out=ballz_out;
  1679.     save_it->b_xoff=b_xoff;
  1680.     save_it->b_yoff=b_yoff;
  1681.     save_it->b_zoff=b_zoff;
  1682.     save_it->save_ballx=save_ballx;
  1683.     save_it->save_bally=save_bally;
  1684.     save_it->save_ballz=save_ballz;
  1685.     save_it->save_ball_poss=save_ball_poss;
  1686.     save_it->good_poss=good_poss;
  1687.     save_it->eff_ballx=eff_ballx;
  1688.     save_it->eff_bally=eff_bally;
  1689.     save_it->eff_ballz=eff_ballz;
  1690.     save_it->prev_ballx=prev_ballx;
  1691.     save_it->prev_bally=prev_bally;
  1692.     save_it->prev_ballz=prev_ballz;
  1693.     save_it->ns_ballx=ns_ballx;
  1694.     save_it->ns_bally=ns_bally;
  1695.     save_it->ns_ballz=ns_ballz;
  1696.     save_it->ball_zspin=ball_zspin;
  1697.     save_it->ball_xyspin=ball_xyspin;
  1698.     save_it->full_zspin=full_zspin;
  1699.     save_it->full_xyspin=full_xyspin;
  1700.     save_it->shoot_x=shoot_x;
  1701.     save_it->shoot_y=shoot_y;
  1702.     save_it->nearest_a=nearest_a;
  1703.     save_it->nearest_b=nearest_b;
  1704.     save_it->old_ltouch=old_ltouch;
  1705.     save_it->old_ball_poss=old_ball_poss;
  1706.     save_it->use_ball_limit=use_ball_limit;
  1707.     save_it->near_path_a=near_path_a;
  1708.     save_it->near_path_b=near_path_b;
  1709.     save_it->zone1_x=zone1_x;
  1710.     save_it->zone1_y=zone1_y;
  1711.     save_it->zone2_x=zone2_x;
  1712.     save_it->zone2_y=zone2_y;
  1713.     save_it->incident_x=incident_x;
  1714.     save_it->incident_y=incident_y;
  1715.     save_it->difficulty=difficulty;
  1716.     save_it->match_mode=match_mode;
  1717.     save_it->dead_ball_cnt=dead_ball_cnt;
  1718.     save_it->defense_a=defense_a;
  1719.     save_it->defense_b=defense_b;
  1720.     save_it->poss_mode=poss_mode;
  1721.     save_it->ball_travel=ball_travel;
  1722.     save_it->select_cnt=select_cnt;
  1723.     save_it->already_there=already_there;
  1724.     save_it->reselection=reselection;
  1725.     save_it->offside_on=offside_on;
  1726.  
  1727. // "C" Vars...
  1728.     save_it->joy1_max_x=joy1_max_x;
  1729.     save_it->joy1_min_x=joy1_min_x;
  1730.     save_it->joy1_max_y=joy1_max_y;
  1731.     save_it->joy1_min_y=joy1_min_y;
  1732.     save_it->joy1_cnt_x=joy1_cnt_x;
  1733.     save_it->joy1_cnt_y=joy1_cnt_y;
  1734.  
  1735.     save_it->joy2_max_x=joy2_max_x;
  1736.     save_it->joy2_min_x=joy2_min_x;
  1737.     save_it->joy2_max_y=joy2_max_y;
  1738.     save_it->joy2_min_y=joy2_min_y;
  1739.     save_it->joy2_cnt_x=joy2_cnt_x;
  1740.     save_it->joy2_cnt_y=joy2_cnt_y;
  1741. }
  1742.  
  1743. /******************************************************************************
  1744. ******************************************************************************/
  1745.  
  1746. void restore_state(save_data *save_it)
  1747. {
  1748.     memcpy(teams,save_it->teams,sizeof(teams));
  1749.     memcpy(&match_time,&save_it->match_time,sizeof(match_time));
  1750.     memcpy(refs,save_it->refs,sizeof(refs));
  1751.     memcpy(speech_tab,save_it->speech_tab,sizeof(speech_tab));
  1752.     memcpy(wguys,save_it->wguys,sizeof(wguys));
  1753.     memcpy(sel_circle,save_it->sel_circle,sizeof(sel_circle));
  1754.     memcpy(burst_timer,save_it->burst_timer,sizeof(burst_timer));
  1755.     memcpy(auto_users_list_a,save_it->auto_users_list_a,sizeof(auto_users_list_a));
  1756.     memcpy(auto_users_list_b,save_it->auto_users_list_b,sizeof(auto_users_list_b));
  1757.     memcpy(rand1_tab,save_it->rand1_tab,sizeof(rand1_tab));
  1758.     memcpy(rand2_tab,save_it->rand2_tab,sizeof(rand2_tab));
  1759.     memcpy(man2man,save_it->man2man,sizeof(man2man));
  1760.     memcpy(glob_str1,save_it->glob_str1,sizeof(glob_str1));
  1761.     memcpy(glob_str2,save_it->glob_str2,sizeof(glob_str2));
  1762.  
  1763.     sub_pending=save_it->sub_pending;
  1764.  
  1765.     return_12=save_it->return_12;
  1766.     shamed_player=save_it->shamed_player;
  1767.     old_min=save_it->old_min;
  1768.     users_left=save_it->users_left;
  1769.     setp_x=save_it->setp_x;
  1770.     setp_y=save_it->setp_y;
  1771.     setp_wait_cnt=save_it->setp_wait_cnt;
  1772.     frame=save_it->frame;
  1773.     kick_off=save_it->kick_off;
  1774.     keep_timer=save_it->keep_timer;
  1775.     stop_clock=save_it->stop_clock;
  1776.     keep_dive=save_it->keep_dive;
  1777.     hold_up_play=save_it->hold_up_play;
  1778.     wall_is_up=save_it->wall_is_up;
  1779.     card_is_out=save_it->card_is_out;
  1780.     crowd_mood_a=save_it->crowd_mood_a;
  1781.     crowd_mood_b=save_it->crowd_mood_b;
  1782.     possession=save_it->possession;
  1783.     poss_held=save_it->poss_held;
  1784.     arrow_on=save_it->arrow_on;
  1785.     logic_cnt=save_it->logic_cnt;
  1786.     ball_move=save_it->ball_move;
  1787.     first_bounce=save_it->first_bounce;
  1788.     swerve=save_it->swerve;
  1789.     spin_cnt=save_it->spin_cnt;
  1790.     spin_ball=save_it->spin_ball;
  1791.     prediction=save_it->prediction;
  1792.     set_xyspin=save_it->set_xyspin;
  1793.     set_zspin=save_it->set_zspin;
  1794.     ball_horz_ang=save_it->ball_horz_ang;
  1795.     ball_vert_ang=save_it->ball_vert_ang;
  1796.     max_sw_factor=save_it->max_sw_factor;
  1797.     swerve_factor=save_it->swerve_factor;
  1798.     rebound_ball=save_it->rebound_ball;
  1799.     headed_ball=save_it->headed_ball;
  1800.     say_names=save_it->say_names;
  1801.     fired_a_shot=save_it->fired_a_shot;
  1802.     comm_pass=save_it->comm_pass;
  1803.     comm_pass_type=save_it->comm_pass_type;
  1804.     keeper_spd=save_it->keeper_spd;
  1805.     keeper_down=save_it->keeper_down;
  1806.     save_direction=save_it->save_direction;
  1807.     keeper_will_save=save_it->keeper_will_save;
  1808.     keeper_on_grnd=save_it->keeper_on_grnd;
  1809.     keeper_contact=save_it->keeper_contact;
  1810.     ball_in_goal=save_it->ball_in_goal;
  1811.     ball_in_hands=save_it->ball_in_hands;
  1812.     game_action=save_it->game_action;
  1813.     throw_cnt=save_it->throw_cnt;
  1814.     team_a_goals=save_it->team_a_goals;
  1815.     team_b_goals=save_it->team_b_goals;
  1816.     last_goal=save_it->last_goal;
  1817.     scorer_running=save_it->scorer_running;
  1818.     just_scored=save_it->just_scored;
  1819.     just_thrown=save_it->just_thrown;
  1820.     goal_scorer=save_it->goal_scorer;
  1821.     pass_type=save_it->pass_type;
  1822.     kick_type=save_it->kick_type;
  1823.     receiver=save_it->receiver;
  1824.     cross_now=save_it->cross_now;
  1825.     auto_select=save_it->auto_select;
  1826.     must_face=save_it->must_face;
  1827.     must_face_time=save_it->must_face_time;
  1828.     must_face_x=save_it->must_face_x;
  1829.     must_face_y=save_it->must_face_y;
  1830.     must_shoot=save_it->must_shoot;
  1831.     chip_pass=save_it->chip_pass;
  1832.     must_pass=save_it->must_pass;
  1833.     must_punt=save_it->must_punt;
  1834.     keeper_a_in_box=save_it->keeper_a_in_box;
  1835.     keeper_b_in_box=save_it->keeper_b_in_box;
  1836.     keeper_steps=save_it->keeper_steps;
  1837.     save_block=save_it->save_block;
  1838.     save_xoff=save_it->save_xoff;
  1839.     save_yoff=save_it->save_yoff;
  1840.     save_zoff=save_it->save_zoff;
  1841.     shot_speed=save_it->shot_speed;
  1842.     scr_x=save_it->scr_x;
  1843.     scr_y=save_it->scr_y;
  1844.     ball_speed=save_it->ball_speed;
  1845.     ball_int_speed=save_it->ball_int_speed;
  1846.     interceptor_a=save_it->interceptor_a;
  1847.     interceptor_b=save_it->interceptor_b;
  1848.     in_cross_area=save_it->in_cross_area;
  1849.     close_in_number=save_it->close_in_number;
  1850.     shooter=save_it->shooter;
  1851.     ball_inair=save_it->ball_inair;
  1852.     super_shot=save_it->super_shot;
  1853.     opponents_near_holder=save_it->opponents_near_holder;
  1854.     opponents_really_close=save_it->opponents_really_close;
  1855.     ball_poss=save_it->ball_poss;
  1856.     sender_1_2=save_it->sender_1_2;
  1857.     ball_still=save_it->ball_still;
  1858.     last_touch=save_it->last_touch;
  1859.     want_pass=save_it->want_pass;
  1860.     before=save_it->before;
  1861.     support_me=save_it->support_me;
  1862.     pre_kp_touch=save_it->pre_kp_touch;
  1863.     prev_touch=save_it->prev_touch;
  1864.     ball_limbo_p=save_it->ball_limbo_p;
  1865.     ball_limbo_on=save_it->ball_limbo_on;
  1866.     ball_limbo_c=save_it->ball_limbo_c;
  1867.     ball_released=save_it->ball_released;
  1868.     cannot_pick_up=save_it->cannot_pick_up;
  1869.     forced=save_it->forced;
  1870.     last_user_a=save_it->last_user_a;
  1871.     last_user_b=save_it->last_user_b;
  1872.     last_plr_a=save_it->last_plr_a;
  1873.     last_plr_b=save_it->last_plr_b;
  1874.     players_off_a=save_it->players_off_a;
  1875.     players_off_b=save_it->players_off_b;
  1876.     want_pass_stat=save_it->want_pass_stat;
  1877.     ball_zone1=save_it->ball_zone1;
  1878.     ball_zone2=save_it->ball_zone2;
  1879.     ball_out_of_play=save_it->ball_out_of_play;
  1880.     receiver_a=save_it->receiver_a;
  1881.     receiver_b=save_it->receiver_b;
  1882.     ready_centre=save_it->ready_centre;
  1883.     shot_attempt=save_it->shot_attempt;
  1884.     force_select=save_it->force_select;
  1885.     heading_ball=save_it->heading_ball;
  1886.     flag=save_it->flag;
  1887.     rep_camera=save_it->rep_camera;
  1888.     sub_camera=save_it->sub_camera;
  1889.     allow_replay=save_it->allow_replay;
  1890.     replay_pos=save_it->replay_pos;
  1891.     old_rep_pos=save_it->old_rep_pos;
  1892.     replay_cnt=save_it->replay_cnt;
  1893.     pitch_sprs=save_it->pitch_sprs;
  1894.     lp_user=save_it->lp_user;
  1895.     fixed_net_user=save_it->fixed_net_user;
  1896.     auto_users_a=save_it->auto_users_a;
  1897.     auto_users_b=save_it->auto_users_b;
  1898.     play_ball_a=save_it->play_ball_a;
  1899.     play_ball_b=save_it->play_ball_b;
  1900.     new_select=save_it->new_select;
  1901.     auto_intercept=save_it->auto_intercept;
  1902.     closest=save_it->closest;
  1903.     f1_down=save_it->f1_down;
  1904.     f2_down=save_it->f2_down;
  1905.     spec_kick_type=save_it->spec_kick_type;
  1906.     setp_hgt=save_it->setp_hgt;
  1907.     setp_power=save_it->setp_power;
  1908.     setp_kick_x=save_it->setp_kick_x;
  1909.     setp_kick_y=save_it->setp_kick_y;
  1910.     setp_bxd=save_it->setp_bxd;
  1911.     setp_byd=save_it->setp_byd;
  1912.     setp_bzd=save_it->setp_bzd;
  1913.     user_taker=save_it->user_taker;
  1914.     user_taker2=save_it->user_taker2;
  1915.     user_controlled=save_it->user_controlled;
  1916.     user_plr=save_it->user_plr;
  1917.     after_touch_on=save_it->after_touch_on;
  1918.     drive_shot=save_it->drive_shot;
  1919.     newk_shot=save_it->newk_shot;
  1920.     wallx=save_it->wallx;
  1921.     wally=save_it->wally;
  1922.     men_in_wall=save_it->men_in_wall;
  1923.     keeper_pos_x=save_it->keeper_pos_x;
  1924.     keeper_pos_y=save_it->keeper_pos_y;
  1925.     centre_guy_1=save_it->centre_guy_1;
  1926.     centre_guy_2=save_it->centre_guy_2;
  1927.     in_range=save_it->in_range;
  1928.     in_header_rng=save_it->in_header_rng;
  1929.     in_shot_rng=save_it->in_shot_rng;
  1930.     taker_x=save_it->taker_x;
  1931.     taker_y=save_it->taker_y;
  1932.     penalty_shot=save_it->penalty_shot;
  1933.     penalties=save_it->penalties;
  1934.     penalty_game=save_it->penalty_game;
  1935.     home_pens_left=save_it->home_pens_left;
  1936.     away_pens_left=save_it->away_pens_left;
  1937.     penalty_counter=save_it->penalty_counter;
  1938.     pen_taker_a=save_it->pen_taker_a;
  1939.     pen_taker_b=save_it->pen_taker_b;
  1940.     penalty_team=save_it->penalty_team;
  1941.     penalty_taker=save_it->penalty_taker;
  1942.     penalty_taker_a=save_it->penalty_taker_a;
  1943.     penalty_taker_b=save_it->penalty_taker_b;
  1944.     setp_taker=save_it->setp_taker;
  1945.     fkick_taker=save_it->fkick_taker;
  1946.     fkick_taker_a=save_it->fkick_taker_a;
  1947.     fkick_taker_b=save_it->fkick_taker_b;
  1948.     gkick_taker=save_it->gkick_taker;
  1949.     goal_kicker_a=save_it->goal_kicker_a;
  1950.     goal_kicker_b=save_it->goal_kicker_b;
  1951.     corner_taker=save_it->corner_taker;
  1952.     corn_kicker_a=save_it->corn_kicker_a;
  1953.     corn_kicker_b=save_it->corn_kicker_b;
  1954.     ktaker=save_it->ktaker;
  1955.     bad_guy=save_it->bad_guy;
  1956.     direct_fk=save_it->direct_fk;
  1957.     play_advantage=save_it->play_advantage;
  1958.     set_piece_on=save_it->set_piece_on;
  1959.     throw_in_taker=save_it->throw_in_taker;
  1960.     main_man=save_it->main_man;
  1961.     player_num=save_it->player_num;
  1962.     savex=save_it->savex;
  1963.     savey=save_it->savey;
  1964.     savez=save_it->savez;
  1965.     shot_acknowledged=save_it->shot_acknowledged;
  1966.     shot_pending=save_it->shot_pending;
  1967.     real_shot=save_it->real_shot;
  1968.     shot_missed=save_it->shot_missed;
  1969.     shot_saved=save_it->shot_saved;
  1970.     drib_opps=save_it->drib_opps;
  1971.     stop_and_face=save_it->stop_and_face;
  1972.     x_face=save_it->x_face;
  1973.     y_face=save_it->y_face;
  1974.     offside_now=save_it->offside_now;
  1975.     can_be_offside=save_it->can_be_offside;
  1976.     ref_accuracy=save_it->ref_accuracy;
  1977.     ref_strictness=save_it->ref_strictness;
  1978.     ref_wait=save_it->ref_wait;
  1979.     tussle_ptr=save_it->tussle_ptr;
  1980.     crowd_a=save_it->crowd_a;
  1981.     crowd_b=save_it->crowd_b;
  1982.     kickoff=save_it->kickoff;
  1983.     end_game=save_it->end_game;
  1984.     team_a=save_it->team_a;
  1985.     team_b=save_it->team_b;
  1986.     last_centre=save_it->last_centre;
  1987.     need_result=save_it->need_result;
  1988.     injury_time=save_it->injury_time;
  1989.     special_move=save_it->special_move;
  1990.     match_half=save_it->match_half;
  1991.     opt_user=save_it->opt_user;
  1992.     opt_team=save_it->opt_team;
  1993.     options_on=save_it->options_on;
  1994.     line_up=save_it->line_up;
  1995.     player_being_subbed=save_it->player_being_subbed;
  1996.     player_on_off=save_it->player_on_off;
  1997.     player_coming_on=save_it->player_coming_on;
  1998.     booking=save_it->booking;
  1999.     subbing_now=save_it->subbing_now;
  2000.     first_update=save_it->first_update;
  2001.     newdx=save_it->newdx;
  2002.     newdy=save_it->newdy;
  2003.     wind_on=save_it->wind_on;
  2004.     wind_d_trend=save_it->wind_d_trend;
  2005.     wind_s_trend=save_it->wind_s_trend;
  2006.     wind_x=save_it->wind_x;
  2007.     wind_y=save_it->wind_y;
  2008.     wind_speed=save_it->wind_speed;
  2009.     init_wind_x=save_it->init_wind_x;
  2010.     init_wind_y=save_it->init_wind_y;
  2011.     init_wind_speed=save_it->init_wind_speed;
  2012.     wind_var_ang=save_it->wind_var_ang;
  2013.     tactics_a=save_it->tactics_a;
  2014.     tactics_b=save_it->tactics_b;
  2015.     old_tac_a=save_it->old_tac_a;
  2016.     old_tac_b=save_it->old_tac_b;
  2017.     afr1=save_it->afr1;
  2018.     afr2=save_it->afr2;
  2019.     man2man_a=save_it->man2man_a;
  2020.     man2man_b=save_it->man2man_b;
  2021.     next_mins=save_it->next_mins;
  2022.     time_factor=save_it->time_factor;
  2023.     clock_running=save_it->clock_running;
  2024.     demo_match=save_it->demo_match;
  2025.     rolling_clock=save_it->rolling_clock;
  2026.     arrow_guy=save_it->arrow_guy;
  2027.     rand_seed=save_it->rand_seed;
  2028.     seed=save_it->seed;
  2029.     man_down=save_it->man_down;
  2030.     launch_type=save_it->launch_type;
  2031.     launch_x=save_it->launch_x;
  2032.     launch_y=save_it->launch_y;
  2033.     ballxdis=save_it->ballxdis;
  2034.     ballydis=save_it->ballydis;
  2035.     ballzdis=save_it->ballzdis;
  2036.     ballx=save_it->ballx;
  2037.     bally=save_it->bally;
  2038.     ballz=save_it->ballz;
  2039.     ballx_out=save_it->ballx_out;
  2040.     bally_out=save_it->bally_out;
  2041.     ballz_out=save_it->ballz_out;
  2042.     b_xoff=save_it->b_xoff;
  2043.     b_yoff=save_it->b_yoff;
  2044.     b_zoff=save_it->b_zoff;
  2045.     save_ballx=save_it->save_ballx;
  2046.     save_bally=save_it->save_bally;
  2047.     save_ballz=save_it->save_ballz;
  2048.     save_ball_poss=save_it->save_ball_poss;
  2049.     good_poss=save_it->good_poss;
  2050.     eff_ballx=save_it->eff_ballx;
  2051.     eff_bally=save_it->eff_bally;
  2052.     eff_ballz=save_it->eff_ballz;
  2053.     prev_ballx=save_it->prev_ballx;
  2054.     prev_bally=save_it->prev_bally;
  2055.     prev_ballz=save_it->prev_ballz;
  2056.     ns_ballx=save_it->ns_ballx;
  2057.     ns_bally=save_it->ns_bally;
  2058.     ns_ballz=save_it->ns_ballz;
  2059.     ball_zspin=save_it->ball_zspin;
  2060.     ball_xyspin=save_it->ball_xyspin;
  2061.     full_zspin=save_it->full_zspin;
  2062.     full_xyspin=save_it->full_xyspin;
  2063.     shoot_x=save_it->shoot_x;
  2064.     shoot_y=save_it->shoot_y;
  2065.     nearest_a=save_it->nearest_a;
  2066.     nearest_b=save_it->nearest_b;
  2067.     old_ltouch=save_it->old_ltouch;
  2068.     old_ball_poss=save_it->old_ball_poss;
  2069.     use_ball_limit=save_it->use_ball_limit;
  2070.     near_path_a=save_it->near_path_a;
  2071.     near_path_b=save_it->near_path_b;
  2072.     zone1_x=save_it->zone1_x;
  2073.     zone1_y=save_it->zone1_y;
  2074.     zone2_x=save_it->zone2_x;
  2075.     zone2_y=save_it->zone2_y;
  2076.     incident_x=save_it->incident_x;
  2077.     incident_y=save_it->incident_y;
  2078.     difficulty=save_it->difficulty;
  2079.     match_mode=save_it->match_mode;
  2080.     dead_ball_cnt=save_it->dead_ball_cnt;
  2081.     defense_a=save_it->defense_a;
  2082.     defense_b=save_it->defense_b;
  2083.     poss_mode=save_it->poss_mode;
  2084.     ball_travel=save_it->ball_travel;
  2085.     select_cnt=save_it->select_cnt;
  2086.     already_there=save_it->already_there;
  2087.     reselection=save_it->reselection;
  2088.     offside_on=save_it->offside_on;
  2089.  
  2090. // "C" Vars...
  2091.     joy1_max_x=save_it->joy1_max_x;
  2092.     joy1_min_x=save_it->joy1_min_x;
  2093.     joy1_max_y=save_it->joy1_max_y;
  2094.     joy1_min_y=save_it->joy1_min_y;
  2095.     joy1_cnt_x=save_it->joy1_cnt_x;
  2096.     joy1_cnt_y=save_it->joy1_cnt_y;
  2097.  
  2098.     joy2_max_x=save_it->joy2_max_x;
  2099.     joy2_min_x=save_it->joy2_min_x;
  2100.     joy2_max_y=save_it->joy2_max_y;
  2101.     joy2_min_y=save_it->joy2_min_y;
  2102.     joy2_cnt_x=save_it->joy2_cnt_x;
  2103.     joy2_cnt_y=save_it->joy2_cnt_y;
  2104. }
  2105.  
  2106. #ifdef EURO96
  2107. /******************************************************************************
  2108. *****************************************************************************/
  2109.  
  2110. void checksum_state()
  2111. {
  2112.     short *ptr=(short *)state_ptr;
  2113.     ptr+=(sizeof(save_data)/sizeof(short));
  2114.     short lim=CHECKSUM_CHUNK;
  2115.  
  2116.     _disable();
  2117. // Must finish checksum before netsend...
  2118.  
  2119.     if (checksum_ptr<ptr)
  2120.     {
  2121. // Some data left to checksum...
  2122.         for (short i=0; i<lim; i++)
  2123.         {
  2124.             state_checksum^=*checksum_ptr++;
  2125.             if (checksum_ptr>=ptr)
  2126.                 i=lim;
  2127.         }
  2128.     }
  2129.     logic_cnt++;
  2130.     _enable();
  2131. }
  2132.  
  2133. /******************************************************************************
  2134. ******************************************************************************/
  2135.  
  2136. void process_state()
  2137. {
  2138.     checksum_state();
  2139.  
  2140.     if (!(logic_cnt%(REAL_SPEED*STATE_INTERVAL)))
  2141.     {
  2142. // Time for a save...
  2143.         if (state_ptr==&state1)
  2144.             state_ptr=&state2;
  2145.         else
  2146.             state_ptr=&state1;
  2147.         save_state(state_ptr);
  2148.         checksum_ptr=(short *)state_ptr;
  2149.     }
  2150. }
  2151.  
  2152. /******************************************************************************
  2153. ******************************************************************************/
  2154.  
  2155. void reset_state(char buff)
  2156. {
  2157. // Buff indicates current (0) or previous state (1)!
  2158.  
  2159.     if (buff)
  2160. // Swap state_ptr...
  2161.         if (state_ptr==&state1)
  2162.             state_ptr=&state2;
  2163.         else
  2164.             state_ptr=&state1;
  2165.  
  2166.     restore_state(state_ptr);
  2167.     checksum_ptr=(short *)state_ptr;
  2168.     state_checksum=0xafaf;
  2169. }
  2170.  
  2171. #endif
  2172.  
  2173. /******************************************************************************
  2174. *****************************************************************************/
  2175.  
  2176. void variable_wind()
  2177. {
  2178. // Variable speed and direction around initial settings...
  2179.  
  2180. // Do dir.
  2181.     if (wind_d_trend>0)
  2182.     {
  2183. // Wind current dir gets further from initial setting...
  2184.         wind_d_trend--;
  2185.         if (wind_var_ang<0)
  2186.             wind_var_ang-=(MAX_WIND_CHANGE*seed/128);
  2187.         else
  2188.             wind_var_ang+=(MAX_WIND_CHANGE*seed/128);
  2189.  
  2190.         wind_x=(init_wind_x*cos(wind_var_ang))-(init_wind_y*sin(wind_var_ang));
  2191.         wind_y=(init_wind_y*cos(wind_var_ang))+(init_wind_x*sin(wind_var_ang));
  2192.     }
  2193.     else
  2194.     {
  2195.         if (wind_d_trend<0)
  2196.         {
  2197. // Wind current dir returns to initial setting...
  2198.             wind_d_trend++;
  2199.             if (wind_var_ang<0)
  2200.                 wind_var_ang+=(MAX_WIND_CHANGE*seed/128);
  2201.             else
  2202.                 wind_var_ang-=(MAX_WIND_CHANGE*seed/128);
  2203.  
  2204.             wind_x=(init_wind_x*cos(wind_var_ang))-(init_wind_y*sin(wind_var_ang));
  2205.             wind_y=(init_wind_y*cos(wind_var_ang))+(init_wind_x*sin(wind_var_ang));
  2206.         }
  2207.         else
  2208.         {
  2209. // New trend...
  2210.             if (ABS(wind_var_ang*128/PI)<seed)
  2211.                 wind_d_trend=WIND_BLUSTERINESS;
  2212.             else
  2213.                 wind_d_trend=-WIND_BLUSTERINESS;
  2214.         }
  2215.     }
  2216.     
  2217.     af_randomize();
  2218.  
  2219. // Do speed.
  2220.     if (wind_s_trend>0)
  2221.     {
  2222. // Increment difference in speed...
  2223.         wind_s_trend--;
  2224.         if ((wind_speed-init_wind_speed)<0)
  2225.         {
  2226.             wind_speed-=(MAX_WIND_S_CHANGE*seed/128);
  2227.             if (wind_speed<0)
  2228.                 wind_speed=0;
  2229.         }
  2230.         else
  2231.         {
  2232.             wind_speed+=(MAX_WIND_S_CHANGE*seed/128);
  2233.             if (wind_speed>128)
  2234.                 wind_speed=128;
  2235.         }
  2236.     }
  2237.     else
  2238.     {
  2239.         if (wind_s_trend<0)
  2240.         {
  2241. // Decrement difference in speed...
  2242.             wind_s_trend++;
  2243.             if ((wind_speed-init_wind_speed)<0)
  2244.             {
  2245.                 wind_speed+=(MAX_WIND_S_CHANGE*seed/128);
  2246.                 if (wind_speed>128)
  2247.                     wind_speed=128;
  2248.             }
  2249.             else
  2250.             {
  2251.                 wind_speed-=(MAX_WIND_S_CHANGE*seed/128);
  2252.                 if (wind_speed<0)
  2253.                     wind_speed=0;
  2254.             }
  2255.         }
  2256.         else
  2257.         {
  2258. // New trend...
  2259.             if (ABS(wind_speed-init_wind_speed)<(seed/2))
  2260.                 wind_s_trend=WIND_GUSTINESS;
  2261.             else
  2262.                 wind_s_trend=-WIND_GUSTINESS;
  2263.         }
  2264.     }
  2265. }
  2266.  
  2267. /******************************************************************************
  2268. ******************************************************************************/
  2269.  
  2270. int coo=0;
  2271. char gkey=0;
  2272.       
  2273. void do_logic()
  2274. {
  2275.     init_pitch_sprites();
  2276.  
  2277. #ifdef SAVE_GAME
  2278.     if (keys[0x11])    // w
  2279.     {
  2280.         save_game();
  2281.     }
  2282.  
  2283.     if (keys[0x2c])    // z
  2284.     {
  2285.         restore_game();
  2286.     }
  2287. #endif
  2288.  
  2289. #ifndef COVERDISK
  2290.     if (debug && key_togs[0x30])        // b
  2291.     {
  2292. // Move ball around with mouse.
  2293.         ReportMouse();
  2294.         ballx=Mouse.x*5-160;
  2295.         bally=Mouse.y*5-160;
  2296.         char key=0;
  2297.         float x,y;
  2298.     }
  2299. #endif
  2300.  
  2301. // Normal logic mode.
  2302. /*
  2303.     if (!match_mode)
  2304.     {
  2305.         if (!--pen_cnt)
  2306.             force_penalty();
  2307.     }
  2308. */
  2309.     frame=(frame) ? 0:1;
  2310.     af_randomize();
  2311.  
  2312.     if (!on_3d)
  2313.     {
  2314.         ReportMouse();
  2315.     }
  2316.  
  2317.     process_subs();
  2318.  
  2319.     if (wind_on<0)
  2320.         variable_wind();        // Get current wind parameters...
  2321.  
  2322.     process_ball();
  2323.  
  2324.     match_rules();
  2325.     keeper_boxes();
  2326.     player_distances();
  2327.     get_nearest();        // near_path_a, near_path_b
  2328.     get_opp_near_ball(ball_poss);
  2329.  
  2330.     process_speech();
  2331.     process_comments();
  2332.     process_flags();
  2333.     process_teams();
  2334.     new_users();
  2335.     select_all_hlites();
  2336.     process_offs();
  2337.  
  2338.     if (!match_mode && comsetp)
  2339.         --comsetp;
  2340. }
  2341.  
  2342. /******************************************************************************
  2343. *****************************************************************************/
  2344.  
  2345. void stop_mf_time()
  2346. {
  2347. /*
  2348.     int cl=clock();
  2349.     int c=cl/CLOCKS_PER_SEC;
  2350.     last_second=c;
  2351.     old_clock=cl;
  2352. */
  2353.     oldcnt=count-1;
  2354. }
  2355.  
  2356. /******************************************************************************
  2357. *****************************************************************************/
  2358.  
  2359. void pause_game()
  2360. {
  2361.     char key=0;
  2362.  
  2363.     do{
  2364.     }while (paused);
  2365.  
  2366.     stop_mf_time();
  2367. }
  2368.  
  2369. /******************************************************************************
  2370. *****************************************************************************/
  2371.  
  2372. extern "C" char calibrated_1,calibrated_2;
  2373.  
  2374. /******************************************************************************
  2375. *****************************************************************************/
  2376.  
  2377. void init_joy1()
  2378. {
  2379.     calibrated_1=FALSE;
  2380.      joy1_min_x=20000;
  2381.      joy1_max_x=0;
  2382.      joy1_min_y=20000;
  2383.      joy1_max_y=0;
  2384. }
  2385.  
  2386. /******************************************************************************
  2387. *****************************************************************************/
  2388.  
  2389. void init_joy2()
  2390. {
  2391.      calibrated_2=FALSE;
  2392.      joy2_min_x=20000;
  2393.      joy2_max_x=0;
  2394.      joy2_min_y=20000;
  2395.      joy2_max_y=0;
  2396. }
  2397.  
  2398. /******************************************************************************
  2399. *****************************************************************************/
  2400.  
  2401. void init_joys()
  2402. {
  2403.      init_joy1();
  2404.      init_joy2();
  2405. }
  2406.  
  2407.  
  2408. void process_keys()
  2409. {
  2410.     if (!demo_match || debug)
  2411.     {
  2412.         while(escape_pending>0)
  2413.         {
  2414.             if (keys[0x15])    // Y
  2415.             {
  2416.                 add_message("Leaving Match!",RED,TRUE);
  2417.                 escape_pending=-1;
  2418.             }
  2419.  
  2420.             if (keys[0x31])    // N
  2421.             {
  2422.                 add_message(" ",WHITE,TRUE);
  2423.                 escape_pending=FALSE;
  2424.                 stop_mf_time();
  2425.             }
  2426.         }
  2427.  
  2428.         if (paused)
  2429.             pause_game();
  2430.  
  2431.         if (keys[0x3b] && keys[0x1d] && joystick1_on)
  2432.         {
  2433. // Ctrl F1...
  2434.             calibrated_1=FALSE;
  2435.             init_joy1();
  2436.             add_message("Auto Calibrating Port 1",WHITE,TRUE);
  2437.         }
  2438.  
  2439.         if (keys[0x3c] && keys[0x1d] && joystick2_on)
  2440.         {
  2441. // Ctrl F2...
  2442.             calibrated_2=FALSE;
  2443.             init_joy2();
  2444.             add_message("Auto Calibrating Port 2",WHITE,TRUE);
  2445.         }
  2446.  
  2447. #ifdef NO_AUTO_SEL
  2448.         if (keys[0x43])            // f9
  2449.             if (key_togs[0x43])
  2450.                 add_message("Manual Switching",WHITE,TRUE);
  2451.             else
  2452.                 add_message("Automatic Switching",WHITE,TRUE);
  2453. #endif
  2454.  
  2455. #ifndef COVERDISK
  2456.         if (debug)
  2457.         {
  2458.             if (keys[0x11] && ball_poss && !match_mode)
  2459.             {
  2460.                 short b=ball_poss;
  2461.                 holder_lose_ball();
  2462.                 init_foul((b<12 ? 13:2),TRUE,TRUE);    // pass no. of fouler.
  2463.             }
  2464.  
  2465.             if (keys[0x0f])
  2466.                 delete_net_user(2);
  2467.  
  2468. /*
  2469.             if (keys[0x14])        // t
  2470.                 if (key_togs[0x14])
  2471.                     tweening=TRUE;
  2472.                 else
  2473.                     tweening=FALSE;
  2474. */
  2475.             if (keys[0x14])        // t
  2476.             {
  2477.                 do; while(keys[0x14]);
  2478.                 if (++xinfo>8)
  2479.                     xinfo=0;
  2480.             }
  2481. /*
  2482.             if (keys[0x0f])        // TAB
  2483.             {
  2484.                 delete_net_user(2);
  2485.                 while(keys[0x14]);
  2486.             }
  2487. */
  2488.             if (keys[0x21])        // f
  2489.             {
  2490. // Fixed speed...
  2491.                 mf_fixed=TRUE;
  2492.                 mf_scale=1;
  2493.             }
  2494.  
  2495.             if (keys[0x22])        // g
  2496.             {
  2497. // Variable speed...
  2498.                 mf_fixed=FALSE;
  2499.             }
  2500.  
  2501.             if (keys[0x4a])        // +
  2502.             {
  2503. // Game Faster...
  2504.                 if (game_speed>0)
  2505.                     game_speed--;
  2506.             }
  2507.  
  2508.             if (keys[0x4e])        // -
  2509.             {
  2510. // Game Slower...
  2511.                 game_speed++;
  2512.             }
  2513.         }
  2514. #endif
  2515.  
  2516.         if (!network_on && !player_on_off && !line_up && match_mode!=SWAP_ENDS)
  2517.         {
  2518.  
  2519. #ifdef SUPPORT_LP
  2520.             if (keys[0x3b] || (users_dir[0].f&8 && users_dir[0].f&4 && !(users_dir[0].f&48)))        // LS + RS
  2521.             {
  2522.                 if (num_of_users>=1)
  2523.                 {
  2524. // User player 1 options...
  2525.                     opt_user=1;
  2526.                 }
  2527.                 else
  2528. // No user players...
  2529.                     opt_user=-1;
  2530.             }
  2531.  
  2532.             if ((keys[0x3c]  || (users_dir[1].f&8 && users_dir[1].f&4) && !(users_dir[0].f&48)) && num_of_users>=2)
  2533.             {
  2534. // User player 2 options...
  2535.                 opt_user=2;
  2536.             }
  2537.  
  2538.             if ((keys[0x3d]  || (users_dir[2].f&8 && users_dir[2].f&4) && !(users_dir[0].f&48)) && num_of_users>=3)
  2539.             {
  2540. // User player 3 options...
  2541.                 opt_user=3;
  2542.             }
  2543.  
  2544.             if ((keys[0x3e]  || (users_dir[3].f&8 && users_dir[3].f&4) && !(users_dir[0].f&48)) && num_of_users>=4)
  2545.             {
  2546. // User player 4 options...
  2547.                 opt_user=4;
  2548.             }
  2549. #else
  2550.             if (keys[0x3b] && !keys[0x1d])                // F1
  2551.             {
  2552.                 if (num_of_users>=1)
  2553.                 {
  2554. // User player 1 options...
  2555.                     opt_user=1;
  2556.                 }
  2557.                 else
  2558. // No user players...
  2559.                     opt_user=-1;
  2560.             }
  2561.  
  2562.             if (keys[0x3c] && !keys[0x1d] && num_of_users>=2)    // F2
  2563.             {
  2564. // User player 2 options...
  2565.                 opt_user=2;
  2566.             }
  2567.  
  2568.             if (keys[0x3d] && !keys[0x1d] && num_of_users>=3)    // F3
  2569.             {
  2570. // User player 3 options...
  2571.                 opt_user=3;
  2572.             }
  2573.  
  2574.             if (keys[0x3e] && !keys[0x1d] && num_of_users>=4)    // F4
  2575.             {
  2576. // User player 4 options...
  2577.                 opt_user=4;
  2578.             }
  2579. #endif
  2580.     
  2581.             if (opt_user)
  2582.             {
  2583.                 if (users[opt_user-1].type==-1)
  2584.                     opt_team=team_a;
  2585.                 else
  2586.                     if (users[opt_user-1].type==-2)
  2587.                         opt_team=team_b;
  2588.                     else
  2589.                         if (users[opt_user-1].type<12)
  2590.                             opt_team=team_a;
  2591.                         else
  2592.                             opt_team=team_b;
  2593.             }
  2594.         }
  2595.     }
  2596.     else
  2597.         if (anykey)
  2598.             end_game=TRUE;
  2599. }
  2600.  
  2601. /******************************************************************************
  2602. *****************************************************************************/
  2603.  
  2604. void animate_players()
  2605. {
  2606.     for (int i=0; i<players; i++)
  2607.     {
  2608.         teams[i].tm_frm+=teams[i].tm_fstep;
  2609.     }
  2610.  
  2611.     for (i=0; i<3; i++)
  2612.     {
  2613.          refs[i].frm+=refs[i].fstep;
  2614.     }
  2615. }
  2616.  
  2617. /******************************************************************************
  2618. *****************************************************************************/
  2619.  
  2620. void update_2d()
  2621. {
  2622.     if    (plot_buffer)
  2623.         plot_cnta=1;
  2624.     else
  2625.         plot_cntb=1;
  2626.  
  2627.     _setplotaction(_GPSET);
  2628.     process_butts();
  2629.     _setplotaction(_GXOR);
  2630.     if (Mouse.b&&1)
  2631.         mouse_fired();
  2632.     draw_ball();
  2633.     draw_team();
  2634.     draw_buffer();
  2635.  
  2636.     plot_buffer=!plot_buffer;
  2637.     draw_buffer();
  2638.     delay(delay_cnt);
  2639.     panel_data();
  2640. }
  2641.  
  2642. /******************************************************************************
  2643. *****************************************************************************/
  2644.  
  2645. void reset_possession()
  2646. {
  2647.     poss_held=0;
  2648.     possession=0;
  2649. }
  2650.  
  2651. /******************************************************************************
  2652. *****************************************************************************/
  2653.  
  2654. void accumulate_possession()
  2655. {
  2656.     if (ball_poss>11)
  2657.     {
  2658. // Team b. currently has possession...
  2659.         poss_held+=(0.0001+(ABS(poss_held)/30));
  2660.         if (poss_held>0.5)
  2661.             poss_held=0.5;
  2662.     }
  2663.     else
  2664.     {
  2665.         if (ball_poss)
  2666. // Team a. currently has possession...
  2667.         {
  2668.             poss_held-=(0.0001+(ABS(poss_held)/30));
  2669.             if (poss_held<-0.5)
  2670.                 poss_held=-0.5;
  2671.         }
  2672.     }
  2673.     
  2674.     if (!ball_poss)
  2675.     {
  2676. // Ball is free...(tend slowly towards 0)
  2677.         poss_held+=(-poss_held/60);
  2678.     }
  2679.  
  2680.     possession+=poss_held;
  2681.     if (possession>1)
  2682.         possession=1;
  2683.     if (possession<-1)
  2684.         possession=-1;
  2685. }
  2686.  
  2687. /******************************************************************************
  2688. *****************************************************************************/
  2689.  
  2690. void process_crowd_noise()
  2691. {
  2692.     if (shot_missed)
  2693.     {
  2694.         if (shot_missed<0)
  2695.         {
  2696. // Missed by a long way...
  2697.             shot_missed++;
  2698.             if (last_touch<12)
  2699.             {
  2700. // team A shot...
  2701.                 crowd_mood_a=CN_BOO;
  2702.                 crowd_mood_b=CN_LAUGH;
  2703.             }
  2704.             else
  2705.             {
  2706. // team B shot...
  2707.                 crowd_mood_a=CN_LAUGH;
  2708.                 crowd_mood_b=CN_BOO;
  2709.             }
  2710.         }
  2711.         else
  2712.         {
  2713. // Near missed...
  2714.             shot_missed--;
  2715.             if (last_touch<12)
  2716.             {
  2717. // team A shot...
  2718.                 crowd_mood_a=CN_MISS;
  2719.                 crowd_mood_b=CN_PENSIVE;
  2720.             }
  2721.             else
  2722.             {
  2723. // team B shot...
  2724.                 crowd_mood_a=CN_PENSIVE;
  2725.                 crowd_mood_b=CN_MISS;
  2726.             }
  2727.         }
  2728.     }
  2729.     else
  2730.     {
  2731.         if (shot_saved)
  2732.         {
  2733. // Shot stopped...
  2734.             shot_saved--;
  2735.             if (last_touch<12)
  2736.             {
  2737. // team A save...
  2738.                 crowd_mood_a=CN_SAVE;
  2739.                 crowd_mood_b=CN_MISS;
  2740.             }
  2741.             else
  2742.             {
  2743. // team B save...
  2744.                 crowd_mood_a=CN_MISS;
  2745.                 crowd_mood_b=CN_SAVE;
  2746.             }
  2747.         }
  2748.         else    
  2749.         {
  2750.             if (card_is_out)
  2751.             {
  2752.                 card_is_out--;
  2753.                 crowd_mood_a=CN_FOWL;
  2754.                 crowd_mood_b=CN_FOWL;
  2755.             }
  2756.             else
  2757.             {
  2758.                 if (match_half>10)
  2759.                 {
  2760. // End of Game...
  2761.                     crowd_mood_a=CN_EXCITED;
  2762.                     crowd_mood_b=CN_EXCITED;
  2763.                 }
  2764.                 else
  2765.                 {
  2766.                     switch(match_mode)
  2767.                     {
  2768.                         case(NORMAL_PLAY):
  2769.                 
  2770.                             if (shot_pending && shot_acknowledged)
  2771.                             {
  2772. // Keeper is reacting to incoming ball...
  2773.                                 if (ballx<prat*40 && ballxdis<0 && last_touch>11)
  2774.                                 {
  2775. // Ball coming left (from team B)...
  2776.                                     crowd_mood_a=CN_PENSIVE;
  2777.                                     crowd_mood_b=CN_EXCITED;
  2778.                                 }
  2779.                                 if (ballx>(pitch_len-(prat*40)) && ballxdis>0 && last_touch<12)
  2780.                                 {
  2781. // Ball coming right (from team A)...
  2782.                                     crowd_mood_a=CN_EXCITED;
  2783.                                     crowd_mood_b=CN_PENSIVE;
  2784.                                 }
  2785.                             }
  2786.                             else
  2787.                             {
  2788.                                 accumulate_possession();
  2789.                     
  2790.                                 if (ball_in_hands && (ball_poss==KP_A || ball_poss==KP_B))
  2791.                                 {
  2792. // Keepers ball...(calm)
  2793.                                     crowd_mood_a=CN_NORMAL;
  2794.                                     crowd_mood_b=CN_NORMAL;
  2795.                                 }
  2796.                                 else
  2797.                                 {
  2798.                                     if ((ballx>(cntspot_x-prat*16)) && (ballx<(cntspot_x+prat*16)))
  2799.                                     {
  2800. // In mid-field...
  2801.                                         crowd_mood_a=CN_NORMAL;
  2802.                                         crowd_mood_b=CN_NORMAL;
  2803.                                     }
  2804.                                     else
  2805.                                     {
  2806.                                         if (ballx<=(cntspot_x-prat*16))
  2807.                                         {
  2808. // Near Goal A...
  2809.                                             if (possession>0.5)
  2810.                                             {
  2811. // Team B has good possession...
  2812.                                                 crowd_mood_a=CN_PENSIVE;
  2813.                                                 crowd_mood_b=CN_EXCITED;
  2814.                                             }
  2815.                                             else
  2816.                                             {
  2817.                                                 if (possession<-0.5)
  2818.                                                 {
  2819. // Defending team A has it under control...
  2820.                                                     crowd_mood_a=CN_NORMAL;
  2821.                                                     crowd_mood_b=CN_NORMAL;
  2822.                                                 }
  2823.                                                 else
  2824.                                                 {
  2825. // No one team has it under control...
  2826.                                                     crowd_mood_a=CN_NORMAL;
  2827.                                                     crowd_mood_b=CN_ENCOURAGING;
  2828.                                                 }
  2829.                                             }
  2830.                                         }
  2831.                                         else
  2832.                                         {
  2833. // Near Goal B...
  2834.                                             if (possession<-0.5)
  2835.                                             {
  2836. // Team A has good possession...
  2837.                                                 crowd_mood_a=CN_EXCITED;
  2838.                                                 crowd_mood_b=CN_PENSIVE;
  2839.                                             }
  2840.                                             else
  2841.                                             {
  2842.                                                 if (possession>0.5)
  2843.                                                 {
  2844. // Defending team B has it under control...
  2845.                                                     crowd_mood_a=CN_NORMAL;
  2846.                                                     crowd_mood_b=CN_NORMAL;
  2847.                                                 }
  2848.                                                 else
  2849.                                                 {
  2850. // No one team has it under control...
  2851.                                                     crowd_mood_a=CN_ENCOURAGING;
  2852.                                                     crowd_mood_b=CN_NORMAL;
  2853.                                                 }
  2854.                                             }
  2855.                                         }
  2856.                                     }
  2857.                                 }
  2858.         
  2859.                                 if (just_scored)
  2860.                                 {
  2861. // someone has scored a goal...
  2862.                                     if (ballx<cntspot_x)
  2863.                                     {
  2864. // Team A. goal...
  2865.                                         if (goal_scorer>11)
  2866.                                         {
  2867. // Team B scores good goal!
  2868.                                             crowd_mood_a=CN_PENSIVE;
  2869.                                             crowd_mood_b=CN_CELEBRATE;
  2870.                                         }
  2871.                                         else
  2872.                                         {
  2873. // Team A scores own goal!
  2874.                                             crowd_mood_a=CN_BOO;
  2875.                                             crowd_mood_b=CN_CELEBRATE;
  2876.                                         }                        
  2877.                                     }
  2878.                                     else
  2879.                                     {
  2880. // Team B. goal...
  2881.                                         if (goal_scorer<12)
  2882.                                         {
  2883. // Team A scores good goal!
  2884.                                             crowd_mood_a=CN_CELEBRATE;
  2885.                                             crowd_mood_b=CN_PENSIVE;
  2886.                                         }
  2887.                                         else
  2888.                                         {
  2889. // Team B scores own goal!
  2890.                                             crowd_mood_a=CN_CELEBRATE;
  2891.                                             crowd_mood_b=CN_BOO;
  2892.                                         }                        
  2893.                                     }
  2894.                                 }
  2895.                             }
  2896.                             break;
  2897.         
  2898.                         case(DF_KICK_B):
  2899.                             if (!men_in_wall)            // Not in shooting range!
  2900.                             {
  2901.                                 if ((ballx>(cntspot_x-prat*16)) && (ballx<(cntspot_x+prat*16)))
  2902.                                 {
  2903. // In mid-field...
  2904.                                     crowd_mood_a=CN_NORMAL;
  2905.                                     crowd_mood_b=CN_NORMAL;
  2906.                                 }
  2907.                                 else
  2908.                                 {
  2909.                                     if (ballx<=(cntspot_x-prat*16))
  2910.                                     {
  2911. // Near Goal A...
  2912.                                         crowd_mood_a=CN_PENSIVE;
  2913.                                         crowd_mood_b=CN_ENCOURAGING;
  2914.                                     }
  2915.                                     else
  2916.                                     {
  2917. // Near Own Goal B...
  2918.                                         crowd_mood_a=CN_NORMAL;
  2919.                                         crowd_mood_b=CN_NORMAL;
  2920.                                     }
  2921.                                 }
  2922.                                 break;
  2923.                             }
  2924.         
  2925.                         case(CORNER_TL):    
  2926.                         case(CORNER_BL):    
  2927.                             crowd_mood_a=CN_PENSIVE;
  2928.                             crowd_mood_b=CN_EXCITED;
  2929.                             break;
  2930.                     
  2931.                         case(DF_KICK_A):
  2932.                             if (!men_in_wall)            // Not in shooting range!
  2933.                             {
  2934.                                 if ((ballx>(cntspot_x-prat*16)) && (ballx<(cntspot_x+prat*16)))
  2935.                                 {
  2936. // In mid-field...
  2937.                                     crowd_mood_a=CN_NORMAL;
  2938.                                     crowd_mood_b=CN_NORMAL;
  2939.                                 }
  2940.                                 else
  2941.                                 {
  2942.                                     if (ballx>=(cntspot_x+prat*16))
  2943.                                     {
  2944. // Near Goal B...
  2945.                                         crowd_mood_a=CN_ENCOURAGING;
  2946.                                         crowd_mood_b=CN_PENSIVE;
  2947.                                     }
  2948.                                     else
  2949.                                     {
  2950. // Near Own Goal A...
  2951.                                         crowd_mood_a=CN_NORMAL;
  2952.                                         crowd_mood_b=CN_NORMAL;
  2953.                                     }
  2954.                                 }
  2955.                                 break;
  2956.                             }
  2957.                         
  2958.                         case(CORNER_TR):    
  2959.                         case(CORNER_BR):    
  2960.                             crowd_mood_a=CN_EXCITED;
  2961.                             crowd_mood_b=CN_PENSIVE;
  2962.                             break;
  2963.         
  2964.                         case(GOAL_KICK_TL):
  2965.                         case(GOAL_KICK_TR):
  2966.                         case(GOAL_KICK_BL):
  2967.                         case(GOAL_KICK_BR):
  2968.                             crowd_mood_a=CN_NORMAL;
  2969.                             crowd_mood_b=CN_NORMAL;
  2970.                             reset_possession();
  2971.                             break;
  2972.         
  2973.                         case(IF_KICK_A):
  2974.                         case(THROW_IN_A):
  2975.                             if ((ballx>(cntspot_x-prat*16)) && (ballx<(cntspot_x+prat*16)))
  2976.                             {
  2977. // In mid-field...
  2978.                                 crowd_mood_a=CN_NORMAL;
  2979.                                 crowd_mood_b=CN_NORMAL;
  2980.                             }
  2981.                             else
  2982.                             {
  2983.                                 if (ballx>=(cntspot_x+prat*16))
  2984.                                 {
  2985. // Near Goal B...
  2986.                                     crowd_mood_a=CN_ENCOURAGING;
  2987.                                     crowd_mood_b=CN_PENSIVE;
  2988.                                 }
  2989.                                 else
  2990.                                 {
  2991. // Near Own Goal A...
  2992.                                     crowd_mood_a=CN_NORMAL;
  2993.                                     crowd_mood_b=CN_NORMAL;
  2994.                                 }
  2995.                             }
  2996.                             break;
  2997.         
  2998.                         case(IF_KICK_B):
  2999.                         case(THROW_IN_B):
  3000.                             if ((ballx>(cntspot_x-prat*16)) && (ballx<(cntspot_x+prat*16)))
  3001.                             {
  3002. // In mid-field...
  3003.                                 crowd_mood_a=CN_NORMAL;
  3004.                                 crowd_mood_b=CN_NORMAL;
  3005.                             }
  3006.                             else
  3007.                             {
  3008.                                 if (ballx<=(cntspot_x-prat*16))
  3009.                                 {
  3010. // Near Goal A...
  3011.                                     crowd_mood_a=CN_PENSIVE;
  3012.                                     crowd_mood_b=CN_ENCOURAGING;
  3013.                                 }
  3014.                                 else
  3015.                                 {
  3016. // Near Own Goal B...
  3017.                                     crowd_mood_a=CN_NORMAL;
  3018.                                     crowd_mood_b=CN_NORMAL;
  3019.                                 }
  3020.                             }
  3021.                             break;
  3022.         
  3023.                         case(PEN_KICK_A):
  3024.                         case(PEN_KICK_B):
  3025.                         case(SWAP_ENDS):
  3026.                             crowd_mood_a=CN_EXCITED;
  3027.                             crowd_mood_b=CN_EXCITED;
  3028.                             break;
  3029.                     
  3030.                         case(CENTRE_A):
  3031.                         case(CENTRE_B):
  3032.                             reset_possession();
  3033.                             if (kickoff)
  3034.                             {
  3035.                                 crowd_mood_a=CN_EXCITED;
  3036.                                 crowd_mood_b=CN_EXCITED;
  3037.                             }
  3038.                             else
  3039.                             {
  3040.                                 crowd_mood_a=CN_NORMAL;
  3041.                                 crowd_mood_b=CN_NORMAL;
  3042.                             }
  3043.                             break;
  3044.                     }
  3045.                 }
  3046.             }
  3047.         }
  3048.     }
  3049. }
  3050.  
  3051. /******************************************************************************
  3052. *****************************************************************************/
  3053.  
  3054. char nothing_happening()
  3055. {
  3056.     if (!match_mode && !just_scored)
  3057.     {
  3058. // In Play...
  3059.         play_fx(PS_FULLTIMEWHISTLE,refs[0].x,refs[0].y);
  3060.  
  3061.  
  3062.  
  3063.         if (shot_pending || dead_ball_cnt || game_action)
  3064.             return(FALSE);            // Crucial moment!
  3065.         else
  3066.             return(TRUE);
  3067.     }
  3068.     else
  3069.     {
  3070.         if (match_mode<=CORNER_BR || match_mode>=PEN_KICK_A)
  3071.             return(FALSE);            // Crucial moment!
  3072.         else
  3073.             if ((match_mode==DF_KICK_B || match_mode==DF_KICK_A) && men_in_wall)
  3074.                 return(FALSE);            // Crucial moment!
  3075.             else
  3076.                 return(TRUE);
  3077.     }
  3078. }
  3079.  
  3080. /******************************************************************************
  3081. *****************************************************************************/
  3082.  
  3083. void watch_match_time()
  3084. {
  3085.     if (golden_goal==2 && !just_scored)
  3086.     {
  3087. // End of sudden death...
  3088.         if (match_half<11)
  3089.         {
  3090. // Start leaving field!
  3091.             play_fx(PS_FULLTIMEWHISTLE,refs[0].x,refs[0].y);
  3092.             last_goal=0;
  3093.             match_mode=SWAP_ENDS;
  3094.             init_match_mode();
  3095.             do_full_time_anim(0);
  3096.             do_fulltime_menu();
  3097.             match_half=11;            // End game!
  3098.             PlayCommentaryMessage(TI_FULLTIME);
  3099.             next_mins=0;
  3100. #ifdef EURO96
  3101.             get_performance();
  3102.             xinfo=9;
  3103.             if (man_of_match)
  3104.                 camera=18;
  3105. #endif
  3106.         }
  3107.     }
  3108.     else
  3109.     {
  3110.     if (match_info.CompetitionType==PENALTIES)
  3111.     {
  3112. // Practice penalties...
  3113.         if (!penalty_game)
  3114.         {
  3115.             if (team_a_goals!=team_b_goals)
  3116.             {
  3117. // Someone has won shoot-out...
  3118.                 if (match_half<11)
  3119.                 {
  3120. // Initialise end of penalty shoot-out...
  3121.                     last_goal=0;
  3122.                     match_mode=SWAP_ENDS;
  3123.                     init_match_mode();
  3124.                     do_full_time_anim(0);
  3125.                     EUROmatch_info.Team_A_penalties=team_a_goals;
  3126.                     EUROmatch_info.Team_B_penalties=team_b_goals;
  3127.                     do_final_score_menu();
  3128.                     match_half=11;            // End game!
  3129.                     PlayCommentaryMessage(TI_FULLTIME);
  3130.                     next_mins=0;
  3131. #ifdef EURO96
  3132.                     get_performance();
  3133.                     xinfo=9;
  3134.                     if (man_of_match)
  3135.                         camera=18;
  3136. #endif
  3137.                 }
  3138.             }
  3139.             else
  3140.             {
  3141. // Initialise penalty shoot-out...
  3142.                 EUROmatch_info.penalties=TRUE;
  3143.                 penalty_game=TRUE;
  3144.                 team_a_goals=0;
  3145.                 team_b_goals=0;
  3146.                 EUROmatch_info.Team_A_penalties=team_a_goals;
  3147.                 EUROmatch_info.Team_B_penalties=team_b_goals;
  3148.                 do_penalty_shootout_menu();
  3149.                 next_mins=0;
  3150.             }
  3151.         }
  3152.     }
  3153.     else
  3154.     {
  3155.          if (match_time.min>=(45+injury_time) && !match_half && nothing_happening())
  3156.         {
  3157. // End of first half! (It's a game of two halves...)
  3158. #ifdef DEMO
  3159.             last_goal=0;
  3160.             match_mode=SWAP_ENDS;
  3161.             init_match_mode();
  3162.             play_fx(PS_FULLTIMEWHISTLE,refs[0].x,refs[0].y);
  3163.             do_full_time_anim(0);
  3164.             do_fulltime_menu();
  3165.             PlayCommentaryMessage(TI_FULLTIME);
  3166.             match_half=11;            // End game!
  3167.             next_mins=0;
  3168. #else
  3169.             match_mode=SWAP_ENDS;
  3170.             last_goal=0;
  3171.             init_match_mode();
  3172.             play_fx(PS_HALFTIMEWHISTLE,refs[0].x,refs[0].y);
  3173.             do_half_time_anim(0);
  3174.             do_halftime_menu();
  3175.             PlayCommentaryMessage(TI_HALFTIME);
  3176.             kickoff=TRUE;
  3177.             next_mins=45;
  3178.  
  3179.             if (practice)
  3180.                 match_half=12;
  3181. #endif
  3182.         }
  3183.         else
  3184.         {
  3185.             if (match_time.min>=(90+injury_time) && match_half==1 && nothing_happening())
  3186.             {
  3187. // End of full time! (Not half mate...)
  3188.                 last_goal=0;
  3189.                 match_mode=SWAP_ENDS;
  3190.                 init_match_mode();
  3191.                 play_fx(PS_FULLTIMEWHISTLE,refs[0].x,refs[0].y);
  3192.  
  3193.                 if (need_result && team_a_goals==team_b_goals)
  3194.                 {
  3195.                     do_extra_time_anim(0);
  3196.                     do_extratime_menu();
  3197.                     EUROmatch_info.extra=TRUE;
  3198.                     kickoff=TRUE;
  3199.                     next_mins=90;
  3200.                 }
  3201.                 else
  3202.                 {
  3203.                     do_full_time_anim(0);
  3204.                     do_fulltime_menu();
  3205.                     PlayCommentaryMessage(TI_FULLTIME);
  3206.                     match_half=11;            // End game!
  3207.                     next_mins=0;
  3208. #ifdef EURO96
  3209.                     get_performance();
  3210.                     xinfo=9;
  3211.                     if (man_of_match)
  3212.                         camera=18;
  3213. #endif
  3214.                 }
  3215.             }
  3216.             else
  3217.             {
  3218.                 if (need_result && match_time.min>=(90+15+injury_time)
  3219.                      && match_half==2 && nothing_happening())
  3220. // End of first half of extra time! (It's a game with more halves...)
  3221.                 {
  3222.                     last_goal=0;
  3223.                     match_mode=SWAP_ENDS;
  3224.                     init_match_mode();
  3225.                     do_half_time_anim(0);
  3226.                     do_halftime_menu();
  3227.                     play_fx(PS_HALFTIMEWHISTLE,refs[0].x,refs[0].y);
  3228.                     kickoff=TRUE;
  3229.                     next_mins=105;
  3230.                 }
  3231.                 else
  3232.                 {
  3233.                     if (!penalty_game && need_result && match_time.min>=(90+30+injury_time)
  3234.                          && match_half==3 && nothing_happening())
  3235. // End of full extra time!
  3236.                     {
  3237.                         play_fx(PS_FULLTIMEWHISTLE,refs[0].x,refs[0].y);
  3238.                         if (need_result && team_a_goals==team_b_goals)
  3239.                         {
  3240.                             EUROmatch_info.penalties=TRUE;
  3241.                             penalty_game=TRUE;
  3242.                             team_a_goals=0;
  3243.                             team_b_goals=0;
  3244.                             EUROmatch_info.Team_A_penalties=team_a_goals;
  3245.                             EUROmatch_info.Team_B_penalties=team_b_goals;
  3246.                             do_penalty_shootout_menu();
  3247.                             next_mins=0;
  3248.                         }
  3249.                         else
  3250.                         {
  3251.                             last_goal=0;
  3252.                             match_mode=SWAP_ENDS;
  3253.                             init_match_mode();
  3254.                             do_full_time_anim(0);
  3255.                             if (EUROmatch_info.penalties)
  3256.                             {
  3257.                                 EUROmatch_info.Team_A_penalties=team_a_goals;
  3258.                                 EUROmatch_info.Team_B_penalties=team_b_goals;
  3259.                                 do_final_score_menu();
  3260.                             }
  3261.                             else
  3262.                                 do_fulltime_menu();
  3263.                             match_half=11;            // End game!
  3264.                             PlayCommentaryMessage(TI_FULLTIME);
  3265.                             next_mins=0;
  3266. #ifdef EURO96
  3267.                             get_performance();
  3268.                             xinfo=9;
  3269.                             if (man_of_match)
  3270.                                 camera=18;
  3271. #endif
  3272.                         }
  3273.                     }
  3274.                 }
  3275.             }
  3276.         }
  3277.     }
  3278.     }
  3279. }
  3280.  
  3281. /******************************************************************************
  3282. *****************************************************************************/
  3283.  
  3284. void setup_alarm()
  3285. {
  3286.     mf_fixed=FALSE;
  3287.     alarm=FALSE;                    // Debug alarm on/off.
  3288.     watch=TRUE;
  3289.     stop_min=45;
  3290.     stop_sec=1;                        // Debug alarm stop.
  3291. }
  3292.  
  3293. /******************************************************************************
  3294. *****************************************************************************/
  3295.  
  3296. void init_wind()
  3297. {
  3298. // Wind stuff...
  3299.     if (EUROmatch_info.wind)
  3300.     {
  3301.         init_wind_x=1;
  3302.         init_wind_y=0;
  3303.         wind_x=init_wind_x;
  3304.         wind_y=init_wind_y;
  3305.         init_wind_speed=EUROmatch_info.wind*30;   // (30,60,90)
  3306.         wind_speed=init_wind_speed;
  3307.         wind_var_ang=0;
  3308.         wind_d_trend=0;
  3309.         wind_s_trend=0;
  3310.  
  3311.         af_randomize();
  3312.         if (!(seed&3))
  3313.             wind_on=-TRUE;        // Variable wind!
  3314.         else
  3315.             wind_on=TRUE;
  3316.  
  3317.         wind_on=TRUE;
  3318.     }
  3319.     else
  3320.         wind_on=FALSE;
  3321. }
  3322.  
  3323. /******************************************************************************
  3324. *****************************************************************************/
  3325.  
  3326. // Get your grubby mits off these routines Andy!
  3327.  
  3328. void NetUserInit()
  3329. {    
  3330.     if (network_on)
  3331.     {
  3332.         // Network init users
  3333.         for (int i=0;i<network_on;i++)
  3334.         {
  3335.             int ctrl;
  3336.             if (i==wConsoleNode)
  3337.             {
  3338.                 ctrl=convert_control(match_info.control_methods[0]);
  3339. //                ctrl=KEY1_CTRL;
  3340. //                calibrate_joy(0,&joy1_cnt_x,&joy1_cnt_y);
  3341.             }
  3342.             else
  3343.                 ctrl=NET_CTRL;
  3344.             if (NetTeams[i]==0)
  3345.                 if (Players[i]==1)
  3346.                     add_team_user(TEAM_A,ctrl);
  3347.                 else
  3348.                     add_fixed_user(Players[i],ctrl);
  3349.             else
  3350.                 if (Players[i]==1)
  3351.                     add_team_user(TEAM_B,ctrl);
  3352.                 else
  3353.                     add_fixed_user(Players[i]+11,ctrl);
  3354.         }
  3355.     }
  3356. }
  3357.  
  3358. int otick;
  3359. void TimerInit()
  3360. {
  3361.     ftick=0;
  3362.     otick=tick=0;
  3363.     old_count=count;
  3364. /*
  3365.     if (!old_mf)
  3366.     {
  3367.         get_user_inputs();
  3368.         process_user_inputs();
  3369.         writeptr++;
  3370.     }
  3371. */
  3372.     while(tick==otick);
  3373. }
  3374.  
  3375. /******************************************************************************
  3376. *****************************************************************************/
  3377.  
  3378. void reset_front()
  3379. {
  3380.     for (int i=0; i<sizeof(cam_array); i++)
  3381.     {
  3382.         if (camera==cam_array[i])
  3383.         {
  3384.             EUROmatch_info.camera=i;
  3385.             match_info.camera_toggle=i;
  3386.             break;
  3387.         }
  3388.     }
  3389. }
  3390.  
  3391. /******************************************************************************
  3392. *****************************************************************************/
  3393.  
  3394. int match(int argc, char **argv)
  3395. {
  3396.     int match_err=FALSE;
  3397.  
  3398.     initialise_vars();
  3399.  
  3400. #ifdef NET_GAME
  3401. // Pseudo net initialisation (not normally used)
  3402.     NetTest();
  3403. #endif
  3404.  
  3405.     if (network_on)
  3406.         old_mf=FALSE;
  3407.     else
  3408.         old_mf=TRUE;
  3409.  
  3410.     offside_on=EUROmatch_info.offside;
  3411.  
  3412.     if (match_info.CompetitionType==PRACTICE)
  3413.     {
  3414.         offside_on=FALSE;
  3415.     }
  3416.  
  3417. // Set up default camera...
  3418.     camera=cam_array[EUROmatch_info.camera];
  3419.     float cd=set_camera_dist;
  3420.     float ch=set_camera_height;
  3421.     change_cam(camera);
  3422.     set_camera_dist=cd;
  3423.     set_camera_height=ch;
  3424.  
  3425. // Set up audio...
  3426.     audio_version=(char)EUROmatch_info.audio;
  3427. // Vidi screen setup...
  3428.     vidi_wall_on=(char)EUROmatch_info.vidi;        // Vidi toggle!
  3429.  
  3430. // Debugging alarm...
  3431.     setup_alarm();
  3432.     
  3433. #ifndef FRONT_END
  3434.     time_factor=4;
  3435. //    debug=TRUE;                                            // Allows return keyboard to dos.
  3436. #else
  3437.     say_names=TRUE;
  3438.     if (network_on)
  3439.         time_factor=time_table[net_half];        // Real minutes duration.
  3440.     else
  3441.         time_factor=time_table[EUROmatch_info.time];    // Real minutes duration.
  3442.  
  3443.     debug=FALSE;                                        // Allows return keyboard to dos.
  3444. #endif
  3445.  
  3446. #ifdef ECTS
  3447.     time_factor=4;
  3448. #endif
  3449. //    debug=TRUE;
  3450. //    time_factor=10;
  3451.  
  3452.     init_wind();
  3453.  
  3454.     gravity=0.60;
  3455.  
  3456.     on_3d=TRUE;
  3457.     digital_joy1=FALSE;
  3458.     digital_joy2=FALSE;
  3459.     close_in_number=2;
  3460.     goal_kicker_a=1;
  3461.     goal_kicker_b=12;
  3462.  
  3463.     fkick_taker_a=0;
  3464.     fkick_taker_b=0;
  3465.  
  3466.     corn_kicker_a=0;
  3467.     corn_kicker_b=0;
  3468.  
  3469. //    _setvideomode(_MRES256COLOR);
  3470.  
  3471.     init_officials();
  3472.  
  3473.     init_match();
  3474.     
  3475.     if (!on_3d)
  3476.     {
  3477.         plot_buffer=TRUE;
  3478.         plot_cnta=0;
  3479.         plot_cntb=0;
  3480.         draw_pitch();
  3481.  
  3482.         pitch_markings();
  3483.         _setcolor(4);
  3484.         draw_buttons();
  3485.         _setcolor(50);
  3486.         _setplotaction(_GXOR);
  3487.         ShowMouse();
  3488.         MouseYlim(140,200-4);
  3489.         MouseXlim(160*2,(320-4)*2);
  3490.     }
  3491.     else
  3492.     {
  3493.         if (init_3d()<0)
  3494.             goto ERR_3D;
  3495.  
  3496.         MouseYlim(0,200);
  3497.         MouseXlim(0,320);
  3498.     }
  3499.  
  3500.     if (audio_version)
  3501.     {
  3502.         InitMatchAudio(rand_seed);
  3503.         if (!LoadPitchSamples())
  3504.             if (!LoadTeamSamples(setup.team_a,HOME_TEAM))
  3505.                 if (!LoadTeamSamples(setup.team_b,AWAY_TEAM))
  3506.                 {
  3507.                     if (match_info.CompetitionType!=PRACTICE)
  3508.                         LoadCommentarySamples();
  3509.  
  3510.                     StartCrowd(HOME_TEAM);
  3511.                     StartCrowd(AWAY_TEAM);
  3512.                 }
  3513.     }
  3514.  
  3515. // Pseudo net user initialisation (not normally used)
  3516.     NetUserInit();
  3517.     users_left=num_of_users;
  3518.  
  3519. // Wait for everyone to get here, set timer & machine factor...
  3520.     readptr=writeptr=0;
  3521.     Network_Play_Ready();
  3522.  
  3523.     setscreen();
  3524.     if (audio_version)
  3525.         PlayWelcomeMessage();
  3526.  
  3527. // Various timing initialisations for network (DO NOT MOVE)
  3528.     TimerInit();
  3529.     mf_scale=omf_scale=0.5;
  3530.     MF=1;
  3531.     old_clock=clock();
  3532.     oldcnt=count;
  3533.  
  3534. // No Dos. keyboard chain!
  3535.     return_doskey=FALSE;
  3536.  
  3537. // Main program loop...
  3538.  
  3539. //    penalty_game=TRUE;
  3540.  
  3541. #ifdef NET_DEBUG
  3542.     if (network_on)
  3543.         opendebugfile();
  3544. #endif
  3545.  
  3546.     do_ref_menu();
  3547.  
  3548. #ifdef FRONT_END
  3549.     if (!num_of_users)
  3550.     {
  3551. // No Players... Rolling match...
  3552.         anykey=FALSE;
  3553.         rolling_clock=80*REAL_SPEED;
  3554.         demo_match=TRUE;
  3555.     }
  3556. #endif
  3557.  
  3558. //    out_mcball_coords();
  3559. //    old_mf=0;    
  3560.     while (in_game && !net_quit)
  3561.     {
  3562.  
  3563. /***********************************************/
  3564.  
  3565.         if (!old_mf)        // New logical loop
  3566.         {
  3567.             int ttick=tick;
  3568.             int tftick=ftick;
  3569.             int twriteptr=writeptr;
  3570.  
  3571.             if ((mf_fixed) || (!on_3d) || (!watch && alarm))
  3572.                 ttick=tick=otick+1,tftick=ftick=0,mf_scale=omf_scale=0;
  3573.  
  3574.             mf_scale=(float)tftick/TIMER_SPEED;
  3575.             MF=(ttick+mf_scale)-(otick+omf_scale);
  3576.             omf_scale=mf_scale;
  3577.             log_factor=MF;                        // Passed to 3d (Logic cycles/update)
  3578.  
  3579.             for (int i=readptr; i!=twriteptr; ++i&=511)
  3580.             {
  3581.                 process_crowd_noise();
  3582.                 if (audio_version)
  3583.                  {
  3584.                     process_crowd_noise();
  3585.                     UpdateCrowd(crowd_mood_a,team_a);
  3586.                     UpdateCrowd(crowd_mood_b,team_b);
  3587.                     UpdateCommentary();
  3588.                 }
  3589.  
  3590.                 wptr=writeptr;
  3591.                 rptr=readptr;
  3592.  
  3593.                 convert_inputs();
  3594.                 readptr++;
  3595.                 readptr&=511;
  3596.                 if (!line_up)
  3597.                 {
  3598.                     do_logic();
  3599.                 }
  3600.                 else
  3601.                 {
  3602.                     line_up--;
  3603.                     animate_players();
  3604.                     if (!line_up)
  3605.                     {
  3606.                         match_mode=CENTRE_A;
  3607.                         init_match_mode();
  3608.                     }
  3609.                 }
  3610. #ifdef EURO96
  3611.                 process_state();
  3612. #else
  3613.                 logic_cnt++;
  3614. #endif
  3615.  
  3616. #ifdef NET_DEBUG
  3617.                 if (network_on)
  3618.                 {
  3619.                     writeplayerdata();
  3620.                     writecontroldata(i);
  3621.                 }
  3622. #endif
  3623.  
  3624.                 new_update_coords();
  3625.                 process_replay();
  3626.                 watch_match_time();
  3627.             }
  3628.             otick=ttick;
  3629.         }
  3630.         else
  3631.         {
  3632.             if ((mf_fixed) || (!on_3d) || (!watch && alarm))
  3633.                 MF=1;
  3634.  
  3635.             mf_scale+=MF;
  3636.             log_factor=MF;                // Passed to 3d(Logic cycles/update)
  3637.  
  3638.             for (float i=(mf_scale); (i>1); i=i-1)
  3639.             {
  3640.                 process_crowd_noise();
  3641.                 if (audio_version)
  3642.                  {
  3643.                     process_crowd_noise();
  3644.                     UpdateCrowd(crowd_mood_a,team_a);
  3645.                     UpdateCrowd(crowd_mood_b,team_b);
  3646.                     UpdateCommentary();
  3647.                 }
  3648.  
  3649.                 get_user_inputs();
  3650.                 process_user_inputs();
  3651.                 writeptr++;
  3652.                 writeptr&=511;
  3653.                 convert_inputs();
  3654.                 readptr++;
  3655.                 readptr&=511;
  3656.                 if (!line_up)
  3657.                 {
  3658.                     do_logic();
  3659.                 }
  3660.                 else
  3661.                 {
  3662.                     line_up--;
  3663.                     animate_players();
  3664.                     if (!line_up)
  3665.                     {
  3666.                         match_mode=CENTRE_A;
  3667.                         init_match_mode();
  3668.                     }
  3669.                 }
  3670.  
  3671. #ifdef EURO96
  3672.                 process_state();
  3673. #else
  3674.                 logic_cnt++;
  3675. #endif
  3676.                 new_update_coords();
  3677.                 process_replay();
  3678.                 watch_match_time();
  3679.                 mf_scale=mf_scale-1;
  3680.             }
  3681.         }
  3682.  
  3683. /***********************************************/
  3684.  
  3685.         if (!(!watch && alarm))
  3686.         {
  3687.             realtime_coords();
  3688.             process_pitch_sprs();
  3689.  
  3690.             if (keys[0x01] && !escape_pending)        // (Esc.)
  3691.             {
  3692.                 escape_pending=TRUE;
  3693.                 add_message("Quit Game Y or N",RED,TRUE);
  3694.             }
  3695.  
  3696.             if (on_3d)
  3697.                 update_3d();
  3698.             else
  3699.                 update_2d();
  3700.  
  3701.             if (on_3d)
  3702.             {
  3703.                 if (old_mf)
  3704.                 {
  3705.                     frame_count();
  3706.                 }
  3707.                 else
  3708.                     updates++;
  3709.  
  3710.                 process_keys();
  3711.             }
  3712.         }
  3713.  
  3714.         if (demo_match && rolling_clock<=0)
  3715.             end_game=TRUE;
  3716.         if ((!on_3d) && (delay_cnt))
  3717.             delay(delay_cnt);
  3718.  
  3719.         if (!in_game && !on_3d)
  3720.         {
  3721.             editor_main();
  3722.             break;
  3723.         }
  3724.  
  3725.         if (escape_pending<0)
  3726.         {
  3727. // Quit Match...
  3728.             net_error=-1;
  3729.             break;
  3730.         }
  3731.  
  3732.         if (end_game)
  3733.             break;
  3734.     }
  3735.  
  3736. #ifdef NET_DEBUG
  3737.     if (network_on)
  3738.         closedebugfile();
  3739. #endif
  3740.  
  3741. // Remove network (if appropriate)
  3742.     Quit_Network_Play();
  3743.  
  3744.     if (audio_version)
  3745.     {
  3746.         StopAudio();
  3747.     }
  3748.  
  3749.     end3d();                    // Goodbye Laurent's crappy heap of runny donkey shit code...
  3750.     freex(replay_tab);
  3751.  
  3752. #ifdef COVERDISK
  3753.     do{
  3754.     }while(keys[0x01]);
  3755.  
  3756.     display_endscr();
  3757. #endif
  3758.  
  3759. // Inform front end on times...
  3760.     if (end_game)
  3761.     {
  3762. // Played Full Match!!!
  3763.         EUROmatch_info.return_mins=-1;
  3764.     }
  3765.     else
  3766.     {
  3767. // Escaped from match!!!
  3768.         EUROmatch_info.return_mins=match_time.min;        
  3769.     }
  3770.  
  3771.     if (audio_version)
  3772.     {
  3773.         FreeCommentarySamples();
  3774.         FreeTeamSamples(AWAY_TEAM);
  3775.         FreeTeamSamples(HOME_TEAM);
  3776.         FreePitchSamples();
  3777.     }
  3778.  
  3779. // Give back front end enviroment stuff...
  3780.     reset_front();
  3781.  
  3782. // Give Dos. keyboard chain!
  3783. #ifdef MEG4
  3784.     release_key_int();
  3785. #endif
  3786.     return_doskey=TRUE;
  3787.  
  3788.     return(FALSE);        // No errors...
  3789.  
  3790.  
  3791. /************ ERRORS *************/
  3792.  
  3793. /*********/
  3794. ERR_3D:;
  3795. // Remove network (if appropriate)
  3796.     net_error=-1;
  3797.     Quit_Network_Play();
  3798.  
  3799.     match_err+=256;
  3800.     goto RETURN_ERR;
  3801.  
  3802. /*********/
  3803.  
  3804. RETURN_ERR:;
  3805.     return(match_err);
  3806. }
  3807.  
  3808.